install.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. =====================
  2. How to install Django
  3. =====================
  4. This document will get you up and running with Django.
  5. Install Python
  6. ==============
  7. Being a Python Web framework, Django requires Python.
  8. It works with any Python version from 2.6 to 2.7 (due to backwards
  9. incompatibilities in Python 3.0, Django does not currently work with
  10. Python 3.0; see :doc:`the Django FAQ </faq/install>` for more
  11. information on supported Python versions and the 3.0 transition).
  12. Get Python at http://www.python.org. If you're running Linux or Mac OS X, you
  13. probably already have it installed.
  14. .. admonition:: Django on Jython
  15. If you use Jython_ (a Python implementation for the Java platform), you'll
  16. need to follow a few additional steps. See :doc:`/howto/jython` for details.
  17. .. _jython: http://jython.org/
  18. .. admonition:: Python on Windows
  19. On Windows, you might need to adjust your ``PATH`` environment variable
  20. to include paths to Python executable and additional scripts. For example,
  21. if your Python is installed in ``C:\Python27\``, the following paths need
  22. to be added to ``PATH``::
  23. C:\Python27\;C:\Python27\Scripts;
  24. Install Apache and mod_wsgi
  25. =============================
  26. If you just want to experiment with Django, skip ahead to the next
  27. section; Django includes a lightweight web server you can use for
  28. testing, so you won't need to set up Apache until you're ready to
  29. deploy Django in production.
  30. If you want to use Django on a production site, use `Apache`_ with
  31. `mod_wsgi`_. mod_wsgi can operate in one of two modes: an embedded
  32. mode and a daemon mode. In embedded mode, mod_wsgi is similar to
  33. mod_perl -- it embeds Python within Apache and loads Python code into
  34. memory when the server starts. Code stays in memory throughout the
  35. life of an Apache process, which leads to significant performance
  36. gains over other server arrangements. In daemon mode, mod_wsgi spawns
  37. an independent daemon process that handles requests. The daemon
  38. process can run as a different user than the Web server, possibly
  39. leading to improved security, and the daemon process can be restarted
  40. without restarting the entire Apache Web server, possibly making
  41. refreshing your codebase more seamless. Consult the mod_wsgi
  42. documentation to determine which mode is right for your setup. Make
  43. sure you have Apache installed, with the mod_wsgi module activated.
  44. Django will work with any version of Apache that supports mod_wsgi.
  45. See :doc:`How to use Django with mod_wsgi </howto/deployment/wsgi/modwsgi>`
  46. for information on how to configure mod_wsgi once you have it
  47. installed.
  48. If you can't use mod_wsgi for some reason, fear not: Django supports many other
  49. deployment options. One is :doc:`uWSGI </howto/deployment/fastcgi>`; it works
  50. very well with `nginx`_. Another is :doc:`FastCGI </howto/deployment/fastcgi>`,
  51. perfect for using Django with servers other than Apache. Additionally, Django
  52. follows the WSGI spec (:pep:`3333`), which allows it to run on a variety of
  53. server platforms. See the `server-arrangements wiki page`_ for specific
  54. installation instructions for each platform.
  55. .. _Apache: http://httpd.apache.org/
  56. .. _nginx: http://nginx.net/
  57. .. _mod_wsgi: http://code.google.com/p/modwsgi/
  58. .. _server-arrangements wiki page: https://code.djangoproject.com/wiki/ServerArrangements
  59. .. _database-installation:
  60. Get your database running
  61. =========================
  62. If you plan to use Django's database API functionality, you'll need to make
  63. sure a database server is running. Django supports many different database
  64. servers and is officially supported with PostgreSQL_, MySQL_, Oracle_ and
  65. SQLite_ (although SQLite doesn't require a separate server to be running).
  66. In addition to the officially supported databases, there are backends provided
  67. by 3rd parties that allow you to use other databases with Django:
  68. * `Sybase SQL Anywhere`_
  69. * `IBM DB2`_
  70. * `Microsoft SQL Server 2005`_
  71. * Firebird_
  72. * ODBC_
  73. The Django versions and ORM features supported by these unofficial backends
  74. vary considerably. Queries regarding the specific capabilities of these
  75. unofficial backends, along with any support queries, should be directed to the
  76. support channels provided by each 3rd party project.
  77. In addition to a database backend, you'll need to make sure your Python
  78. database bindings are installed.
  79. * If you're using PostgreSQL, you'll need the ``postgresql_psycopg2`` package.
  80. You might want to refer to our :ref:`PostgreSQL notes <postgresql-notes>` for
  81. further technical details specific to this database.
  82. If you're on Windows, check out the unofficial `compiled Windows version`_.
  83. * If you're using MySQL, you'll need MySQLdb_, version 1.2.1p2 or higher. You
  84. will also want to read the database-specific :ref:`notes for the MySQL
  85. backend <mysql-notes>`.
  86. * If you're using Oracle, you'll need a copy of cx_Oracle_, but please
  87. read the database-specific :ref:`notes for the Oracle backend <oracle-notes>`
  88. for important information regarding supported versions of both Oracle and
  89. ``cx_Oracle``.
  90. * If you're using an unofficial 3rd party backend, please consult the
  91. documentation provided for any additional requirements.
  92. If you plan to use Django's ``manage.py syncdb`` command to
  93. automatically create database tables for your models, you'll need to
  94. ensure that Django has permission to create and alter tables in the
  95. database you're using; if you plan to manually create the tables, you
  96. can simply grant Django ``SELECT``, ``INSERT``, ``UPDATE`` and
  97. ``DELETE`` permissions. On some databases, Django will need
  98. ``ALTER TABLE`` privileges during ``syncdb`` but won't issue
  99. ``ALTER TABLE`` statements on a table once ``syncdb`` has created it.
  100. If you're using Django's :doc:`testing framework</topics/testing>` to test database queries,
  101. Django will need permission to create a test database.
  102. .. _PostgreSQL: http://www.postgresql.org/
  103. .. _MySQL: http://www.mysql.com/
  104. .. _psycopg: http://initd.org/pub/software/psycopg/
  105. .. _compiled Windows version: http://stickpeople.com/projects/python/win-psycopg/
  106. .. _MySQLdb: http://sourceforge.net/projects/mysql-python
  107. .. _SQLite: http://www.sqlite.org/
  108. .. _pysqlite: http://trac.edgewall.org/wiki/PySqlite
  109. .. _cx_Oracle: http://cx-oracle.sourceforge.net/
  110. .. _Oracle: http://www.oracle.com/
  111. .. _Sybase SQL Anywhere: http://code.google.com/p/sqlany-django/
  112. .. _IBM DB2: http://code.google.com/p/ibm-db/
  113. .. _Microsoft SQL Server 2005: http://code.google.com/p/django-mssql/
  114. .. _Firebird: http://code.google.com/p/django-firebird/
  115. .. _ODBC: http://code.google.com/p/django-pyodbc/
  116. .. _removing-old-versions-of-django:
  117. Remove any old versions of Django
  118. =================================
  119. If you are upgrading your installation of Django from a previous version,
  120. you will need to uninstall the old Django version before installing the
  121. new version.
  122. If you installed Django using ``setup.py install``, uninstalling
  123. is as simple as deleting the ``django`` directory from your Python
  124. ``site-packages``.
  125. If you installed Django from a Python egg, remove the Django ``.egg`` file,
  126. and remove the reference to the egg in the file named ``easy-install.pth``.
  127. This file should also be located in your ``site-packages`` directory.
  128. .. _finding-site-packages:
  129. .. admonition:: Where are my ``site-packages`` stored?
  130. The location of the ``site-packages`` directory depends on the operating
  131. system, and the location in which Python was installed. To find out your
  132. system's ``site-packages`` location, execute the following:
  133. .. code-block:: bash
  134. python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
  135. (Note that this should be run from a shell prompt, not a Python interactive
  136. prompt.)
  137. Some Debian-based Linux distributions have separate ``site-packages``
  138. directories for user-installed packages, such as when installing Django
  139. from a downloaded tarball. The command listed above will give you the
  140. system's ``site-packages``, the user's directory can be found in
  141. ``/usr/local/lib/`` instead of ``/usr/lib/``.
  142. .. _install-django-code:
  143. Install the Django code
  144. =======================
  145. Installation instructions are slightly different depending on whether you're
  146. installing a distribution-specific package, downloading the latest official
  147. release, or fetching the latest development version.
  148. It's easy, no matter which way you choose.
  149. Installing a distribution-specific package
  150. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151. Check the :doc:`distribution specific notes </misc/distributions>` to see if
  152. your platform/distribution provides official Django packages/installers.
  153. Distribution-provided packages will typically allow for automatic installation
  154. of dependencies and easy upgrade paths.
  155. .. _installing-official-release:
  156. Installing an official release with ``pip``
  157. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158. This is the recommended way to install Django.
  159. 1. Install pip_. The easiest is to use the `standalone pip installer`_. If your
  160. distribution already has ``pip`` installed, you might need to update it if
  161. it's outdated. (If it's outdated, you'll know because installation won't
  162. work.)
  163. 2. (optional) Take a look at virtualenv_ and virtualenvwrapper_. These tools
  164. provide isolated Python environments, which are more practical than
  165. installing packages systemwide. They also allow installing packages
  166. without administrator privileges. It's up to you to decide if you want to
  167. learn and use them.
  168. 3. If you're using Linux, Mac OS X or some other flavor of Unix, enter the
  169. command ``sudo pip install Django`` at the shell prompt. If you're using
  170. Windows, start a command shell with administrator privileges and run
  171. the command ``pip install Django``. This will install Django in your Python
  172. installation's ``site-packages`` directory.
  173. If you're using a virtualenv, you don't need ``sudo`` or administrator
  174. privileges, and this will install Django in the virtualenv's
  175. ``site-packages`` directory.
  176. .. _pip: http://www.pip-installer.org/
  177. .. _virtualenv: http://www.virtualenv.org/
  178. .. _virtualenvwrapper: http://www.doughellmann.com/docs/virtualenvwrapper/
  179. .. _standalone pip installer: http://www.pip-installer.org/en/latest/installing.html#using-the-installer
  180. Installing an official release manually
  181. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  182. 1. Download the latest release from our `download page`_.
  183. 2. Untar the downloaded file (e.g. ``tar xzvf Django-X.Y.tar.gz``,
  184. where ``X.Y`` is the version number of the latest release).
  185. If you're using Windows, you can download the command-line tool
  186. bsdtar_ to do this, or you can use a GUI-based tool such as 7-zip_.
  187. 3. Change into the directory created in step 2 (e.g. ``cd Django-X.Y``).
  188. 4. If you're using Linux, Mac OS X or some other flavor of Unix, enter the
  189. command ``sudo python setup.py install`` at the shell prompt. If you're
  190. using Windows, start a command shell with administrator privileges and
  191. run the command ``python setup.py install``. This will install Django in
  192. your Python installation's ``site-packages`` directory.
  193. .. _download page: https://www.djangoproject.com/download/
  194. .. _bsdtar: http://gnuwin32.sourceforge.net/packages/bsdtar.htm
  195. .. _7-zip: http://www.7-zip.org/
  196. .. _installing-development-version:
  197. Installing the development version
  198. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  199. .. admonition:: Tracking Django development
  200. If you decide to use the latest development version of Django,
  201. you'll want to pay close attention to `the development timeline`_,
  202. and you'll want to keep an eye on `the list of
  203. backwards-incompatible changes`_. This will help you stay on top
  204. of any new features you might want to use, as well as any changes
  205. you'll need to make to your code when updating your copy of Django.
  206. (For stable releases, any necessary changes are documented in the
  207. release notes.)
  208. .. _the development timeline: https://code.djangoproject.com/timeline
  209. .. _the list of backwards-incompatible changes: https://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
  210. If you'd like to be able to update your Django code occasionally with the
  211. latest bug fixes and improvements, follow these instructions:
  212. 1. Make sure that you have Subversion_, Git_, or Mercurial_ installed, and
  213. that you can run its commands from a shell. (Enter ``svn help``,
  214. ``git help``, or ``hg help`` at a shell prompt to test this.) Note that
  215. the Subversion repository is the canonical source for the official
  216. Git and Mercurial repositories and as such will always be the most up-to-date.
  217. 2. Check out Django's main development branch (the 'trunk') like so:
  218. .. code-block:: bash
  219. # Subversion
  220. svn co https://code.djangoproject.com/svn/django/trunk/ django-trunk
  221. Mirrors of the Subversion repository can be obtained like so:
  222. .. code-block:: bash
  223. # Git (requires version 1.6.6 or later)
  224. git clone https://github.com/django/django.git
  225. # or (works with all versions)
  226. git clone git://github.com/django/django.git
  227. # Mercurial
  228. hg clone https://bitbucket.org/django/django
  229. .. warning ::
  230. These mirrors should be updated every 5 minutes but aren't guaranteed
  231. to be up-to-date since they are hosted on external services.
  232. 3. Next, make sure that the Python interpreter can load Django's code. The most
  233. convenient way to do this is to `modify Python's search path`_. Add a ``.pth``
  234. file containing the full path to the ``django-trunk`` directory to your
  235. system's ``site-packages`` directory. For example, on a Unix-like system:
  236. .. code-block:: bash
  237. echo WORKING-DIR/django-trunk > SITE-PACKAGES-DIR/django.pth
  238. (In the above line, change ``SITE-PACKAGES-DIR`` to match the location of
  239. your system's ``site-packages`` directory, as explained in the
  240. :ref:`Where are my site-packages stored? <finding-site-packages>` section
  241. above. Change ``WORKING-DIR/django-trunk`` to match the full path to your
  242. new ``django-trunk`` directory.)
  243. 4. On Unix-like systems, create a symbolic link to the file
  244. ``django-trunk/django/bin/django-admin.py`` in a directory on your system
  245. path, such as ``/usr/local/bin``. For example:
  246. .. code-block:: bash
  247. ln -s WORKING-DIR/django-trunk/django/bin/django-admin.py /usr/local/bin
  248. (In the above line, change WORKING-DIR to match the full path to your new
  249. ``django-trunk`` directory.)
  250. This simply lets you type ``django-admin.py`` from within any directory,
  251. rather than having to qualify the command with the full path to the file.
  252. On Windows systems, the same result can be achieved by copying the file
  253. ``django-trunk/django/bin/django-admin.py`` to somewhere on your system
  254. path, for example ``C:\Python27\Scripts``.
  255. .. warning::
  256. Don't run ``sudo python setup.py install``, because you've already
  257. carried out the equivalent actions in steps 3 and 4. Furthermore, this is
  258. known to cause problems when updating to a more recent version of Django.
  259. When you want to update your copy of the Django source code, just run the
  260. command ``svn update`` from within the ``django-trunk`` directory. When you do
  261. this, Subversion will automatically download any changes. The equivalent
  262. command for Git is ``git pull``, and for Mercurial ``hg pull --update``.
  263. .. _Subversion: http://subversion.tigris.org/
  264. .. _Git: http://git-scm.com/
  265. .. _Mercurial: http://mercurial.selenic.com/
  266. .. _`modify Python's search path`: http://docs.python.org/install/index.html#modifying-python-s-search-path