install.txt 12 KB

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