install.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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.4 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. Install Apache and mod_wsgi
  19. =============================
  20. If you just want to experiment with Django, skip ahead to the next
  21. section; Django includes a lightweight Web server you can use for
  22. testing, so you won't need to set up Apache until you're ready to
  23. deploy Django in production.
  24. If you want to use Django on a production site, use Apache with
  25. `mod_wsgi`_. mod_wsgi can operate in one of two modes: an embedded
  26. mode and a daemon mode. In embedded mode, mod_wsgi is similar to
  27. mod_perl -- it embeds Python within Apache and loads Python code into
  28. memory when the server starts. Code stays in memory throughout the
  29. life of an Apache process, which leads to significant performance
  30. gains over other server arrangements. In daemon mode, mod_wsgi spawns
  31. an independent daemon process that handles requests. The daemon
  32. process can run as a different user than the Web server, possibly
  33. leading to improved security, and the daemon process can be restarted
  34. without restarting the entire Apache Web server, possibly making
  35. refreshing your codebase more seamless. Consult the mod_wsgi
  36. documentation to determine which mode is right for your setup. Make
  37. sure you have Apache installed, with the mod_wsgi module activated.
  38. Django will work with any version of Apache that supports mod_wsgi.
  39. See :doc:`How to use Django with mod_wsgi </howto/deployment/modwsgi>`
  40. for information on how to configure mod_wsgi once you have it
  41. installed.
  42. If you can't use mod_wsgi for some reason, fear not: Django supports
  43. many other deployment options. Another option is :doc:`FastCGI
  44. </howto/deployment/fastcgi>`, perfect for using Django with servers
  45. other than Apache. Additionally, Django follows the WSGI_ spec, which
  46. allows it to run on a variety of server platforms. See the
  47. `server-arrangements wiki page`_ for specific installation
  48. instructions for each platform.
  49. .. _Apache: http://httpd.apache.org/
  50. .. _mod_wsgi: http://code.google.com/p/modwsgi/
  51. .. _WSGI: http://www.python.org/dev/peps/pep-0333/
  52. .. _server-arrangements wiki page: http://code.djangoproject.com/wiki/ServerArrangements
  53. .. _database-installation:
  54. Get your database running
  55. =========================
  56. If you plan to use Django's database API functionality, you'll need to make
  57. sure a database server is running. Django supports many different database
  58. servers and is officially supported with PostgreSQL_, MySQL_, Oracle_ and
  59. SQLite_ (although SQLite doesn't require a separate server to be running).
  60. In addition to the officially supported databases, there are backends provided
  61. by 3rd parties that allow you to use other databases with Django:
  62. * `Sybase SQL Anywhere`_
  63. * `IBM DB2`_
  64. * `Microsoft SQL Server 2005`_
  65. * Firebird_
  66. * ODBC_
  67. The Django versions and ORM features supported by these unofficial backends
  68. vary considerably. Queries regarding the specific capabilities of these
  69. unofficial backends, along with any support queries, should be directed to the
  70. support channels provided by each 3rd party project.
  71. In addition to a database backend, you'll need to make sure your Python
  72. database bindings are installed.
  73. * If you're using PostgreSQL, you'll need the psycopg_ package. Django supports
  74. both version 1 and 2. (When you configure Django's database layer, specify
  75. either ``postgresql`` [for version 1] or ``postgresql_psycopg2`` [for version 2].)
  76. If you're on Windows, check out the unofficial `compiled Windows version`_.
  77. * If you're using MySQL, you'll need MySQLdb_, version 1.2.1p2 or higher. You
  78. will also want to read the database-specific notes for the :doc:`MySQL
  79. backend </ref/databases>`.
  80. * If you're using SQLite and Python 2.4, you'll need pysqlite_. Use version
  81. 2.0.3 or higher. Python 2.5 ships with an SQLite wrapper in the standard
  82. library, so you don't need to install anything extra in that case. Please
  83. read the SQLite backend :ref:`notes<sqlite-notes>`.
  84. * If you're using Oracle, you'll need a copy of cx_Oracle_, but please
  85. read the database-specific notes for the
  86. :ref:`Oracle backend <oracle-notes>` for important information
  87. regarding supported versions of both Oracle and ``cx_Oracle``.
  88. * If you're using an unofficial 3rd party backend, please consult the
  89. documentation provided for any additional requirements.
  90. If you plan to use Django's ``manage.py syncdb`` command to
  91. automatically create database tables for your models, you'll need to
  92. ensure that Django has permission to create and alter tables in the
  93. database you're using; if you plan to manually create the tables, you
  94. can simply grant Django ``SELECT``, ``INSERT``, ``UPDATE`` and
  95. ``DELETE`` permissions. On some databases, Django will need
  96. ``ALTER TABLE`` privileges during ``syncdb`` but won't issue
  97. ``ALTER TABLE`` statements on a table once ``syncdb`` has created it.
  98. If you're using Django's :doc:`testing framework</topics/testing>` to test database queries,
  99. Django will need permission to create a test database.
  100. .. _PostgreSQL: http://www.postgresql.org/
  101. .. _MySQL: http://www.mysql.com/
  102. .. _Django's ticket system: http://code.djangoproject.com/report/1
  103. .. _psycopg: http://initd.org/pub/software/psycopg/
  104. .. _compiled Windows version: http://stickpeople.com/projects/python/win-psycopg/
  105. .. _MySQLdb: http://sourceforge.net/projects/mysql-python
  106. .. _SQLite: http://www.sqlite.org/
  107. .. _pysqlite: http://trac.edgewall.org/wiki/PySqlite
  108. .. _cx_Oracle: http://cx-oracle.sourceforge.net/
  109. .. _Oracle: http://www.oracle.com/
  110. .. _Sybase SQL Anywhere: http://code.google.com/p/sqlany-django/
  111. .. _IBM DB2: http://code.google.com/p/ibm-db/
  112. .. _Microsoft SQL Server 2005: http://code.google.com/p/django-mssql/
  113. .. _Firebird: http://code.google.com/p/django-firebird/
  114. .. _ODBC: http://code.google.com/p/django-pyodbc/
  115. .. _removing-old-versions-of-django:
  116. Remove any old versions of Django
  117. =================================
  118. If you are upgrading your installation of Django from a previous version,
  119. you will need to uninstall the old Django version before installing the
  120. new version.
  121. If you installed Django using ``setup.py install``, uninstalling
  122. is as simple as deleting the ``django`` directory from your Python
  123. ``site-packages``.
  124. If you installed Django from a Python egg, remove the Django ``.egg`` file,
  125. and remove the reference to the egg in the file named ``easy-install.pth``.
  126. This file should also be located in your ``site-packages`` directory.
  127. .. admonition:: Where are my ``site-packages`` stored?
  128. The location of the ``site-packages`` directory depends on the operating
  129. system, and the location in which Python was installed. To find out your
  130. system's ``site-packages`` location, execute the following:
  131. .. code-block:: bash
  132. python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
  133. (Note that this should be run from a shell prompt, not a Python interactive
  134. prompt.)
  135. .. _install-django-code:
  136. Install the Django code
  137. =======================
  138. Installation instructions are slightly different depending on whether you're
  139. installing a distribution-specific package, downloading the latest official
  140. release, or fetching the latest development version.
  141. It's easy, no matter which way you choose.
  142. Installing a distribution-specific package
  143. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144. Check the :doc:`distribution specific notes </misc/distributions>` to see if your
  145. platform/distribution provides official Django packages/installers.
  146. Distribution-provided packages will typically allow for automatic installation
  147. of dependencies and easy upgrade paths.
  148. .. _installing-official-release:
  149. Installing an official release
  150. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151. 1. Download the latest release from our `download page`_.
  152. 2. Untar the downloaded file (e.g. ``tar xzvf Django-NNN.tar.gz``,
  153. where ``NNN`` is the version number of the latest release).
  154. If you're using Windows, you can download the command-line tool
  155. bsdtar_ to do this, or you can use a GUI-based tool such as 7-zip_.
  156. 3. Change into the directory created in step 2 (e.g. ``cd Django-NNN``).
  157. 4. If you're using Linux, Mac OS X or some other flavor of Unix, enter
  158. the command ``sudo python setup.py install`` at the shell prompt.
  159. If you're using Windows, start up a command shell with administrator
  160. privileges and run the command ``setup.py install``.
  161. These commands will install Django in your Python installation's
  162. ``site-packages`` directory.
  163. .. _bsdtar: http://gnuwin32.sourceforge.net/packages/bsdtar.htm
  164. .. _7-zip: http://www.7-zip.org/
  165. .. _installing-development-version:
  166. Installing the development version
  167. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. .. admonition:: Tracking Django development
  169. If you decide to use the latest development version of Django,
  170. you'll want to pay close attention to `the development timeline`_,
  171. and you'll want to keep an eye on `the list of
  172. backwards-incompatible changes`_. This will help you stay on top
  173. of any new features you might want to use, as well as any changes
  174. you'll need to make to your code when updating your copy of Django.
  175. (For stable releases, any necessary changes are documented in the
  176. release notes.)
  177. .. _the development timeline: http://code.djangoproject.com/timeline
  178. .. _the list of backwards-incompatible changes: http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
  179. If you'd like to be able to update your Django code occasionally with the
  180. latest bug fixes and improvements, follow these instructions:
  181. 1. Make sure that you have Subversion_ installed, and that you can run its
  182. commands from a shell. (Enter ``svn help`` at a shell prompt to test
  183. this.)
  184. 2. Check out Django's main development branch (the 'trunk') like so:
  185. .. code-block:: bash
  186. svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
  187. 3. Next, make sure that the Python interpreter can load Django's code. There
  188. are various ways of accomplishing this. One of the most convenient, on
  189. Linux, Mac OSX or other Unix-like systems, is to use a symbolic link:
  190. .. code-block:: bash
  191. ln -s WORKING-DIR/django-trunk/django SITE-PACKAGES-DIR/django
  192. (In the above line, change ``SITE-PACKAGES-DIR`` to match the location of
  193. your system's ``site-packages`` directory, as explained in the
  194. "Where are my ``site-packages`` stored?" section above. Change WORKING-DIR
  195. to match the full path to your new ``django-trunk`` directory.)
  196. Alternatively, you can define your ``PYTHONPATH`` environment variable
  197. so that it includes the ``django-trunk`` directory. This is perhaps the
  198. most convenient solution on Windows systems, which don't support symbolic
  199. links. (Environment variables can be defined on Windows systems `from the
  200. Control Panel`_.)
  201. .. admonition:: What about Apache and mod_wsgi?
  202. If you take the approach of setting ``PYTHONPATH``, you'll need
  203. to remember to do the same thing in your WSGI application once
  204. you deploy your production site. Do this by appending to
  205. ``sys.path`` in your WSGI application.
  206. More information about deployment is available, of course, in our
  207. :doc:`How to use Django with mod_wsgi </howto/deployment/modwsgi>`
  208. documentation.
  209. 4. On Unix-like systems, create a symbolic link to the file
  210. ``django-trunk/django/bin/django-admin.py`` in a directory on your system
  211. path, such as ``/usr/local/bin``. For example:
  212. .. code-block:: bash
  213. ln -s WORKING-DIR/django-trunk/django/bin/django-admin.py /usr/local/bin
  214. (In the above line, change WORKING-DIR to match the full path to your new
  215. ``django-trunk`` directory.)
  216. This simply lets you type ``django-admin.py`` from within any directory,
  217. rather than having to qualify the command with the full path to the file.
  218. On Windows systems, the same result can be achieved by copying the file
  219. ``django-trunk/django/bin/django-admin.py`` to somewhere on your system
  220. path, for example ``C:\Python24\Scripts``.
  221. You *don't* have to run ``python setup.py install``, because you've already
  222. carried out the equivalent actions in steps 3 and 4.
  223. When you want to update your copy of the Django source code, just run the
  224. command ``svn update`` from within the ``django-trunk`` directory. When you do
  225. this, Subversion will automatically download any changes.
  226. .. _`download page`: http://www.djangoproject.com/download/
  227. .. _Subversion: http://subversion.tigris.org/
  228. .. _from the Control Panel: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_environmnt_addchange_variable.mspx