install.txt 15 KB

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