install.txt 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. See
  8. :ref:`faq-python-version-support` for details.
  9. Get the latest version of Python at https://www.python.org/download/ or with
  10. your operating system's package manager.
  11. .. admonition:: Django on Jython
  12. If you use Jython_ (a Python implementation for the Java platform), you'll
  13. need to follow a few additional steps. See :doc:`/howto/jython` for details.
  14. .. _jython: http://jython.org/
  15. .. admonition:: Python on Windows
  16. If you are just starting with Django and using Windows, you may find
  17. :doc:`/howto/windows` useful.
  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/wsgi/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 many other
  43. deployment options. One is :doc:`uWSGI </howto/deployment/wsgi/uwsgi>`; it works
  44. very well with `nginx`_. Additionally, Django follows the WSGI spec
  45. (:pep:`3333`), which allows it to run on a variety of server platforms.
  46. .. _Apache: https://httpd.apache.org/
  47. .. _nginx: http://nginx.org/
  48. .. _mod_wsgi: http://www.modwsgi.org/
  49. .. _database-installation:
  50. Get your database running
  51. =========================
  52. If you plan to use Django's database API functionality, you'll need to make
  53. sure a database server is running. Django supports many different database
  54. servers and is officially supported with PostgreSQL_, MySQL_, Oracle_ and
  55. SQLite_.
  56. If you are developing a simple project or something you don't plan to deploy
  57. in a production environment, SQLite is generally the simplest option as it
  58. doesn't require running a separate server. However, SQLite has many differences
  59. from other databases, so if you are working on something substantial, it's
  60. recommended to develop with the same database as you plan on using in
  61. production.
  62. In addition to the officially supported databases, there are :ref:`backends
  63. provided by 3rd parties <third-party-notes>` that allow you to use other
  64. databases with Django.
  65. In addition to a database backend, you'll need to make sure your Python
  66. database bindings are installed.
  67. * If you're using PostgreSQL, you'll need the `psycopg2`_ package. Refer to the
  68. :ref:`PostgreSQL notes <postgresql-notes>` for further details.
  69. * If you're using MySQL, you'll need a :ref:`DB API driver
  70. <mysql-db-api-drivers>` like ``mysqlclient``. See :ref:`notes for the MySQL
  71. backend <mysql-notes>` for details.
  72. * If you're using SQLite you might want to read the :ref:`SQLite backend notes
  73. <sqlite-notes>`.
  74. * If you're using Oracle, you'll need a copy of cx_Oracle_, but please
  75. read the :ref:`notes for the Oracle backend <oracle-notes>` for details
  76. regarding supported versions of both Oracle and ``cx_Oracle``.
  77. * If you're using an unofficial 3rd party backend, please consult the
  78. documentation provided for any additional requirements.
  79. If you plan to use Django's ``manage.py migrate`` command to automatically
  80. create database tables for your models (after first installing Django and
  81. creating a project), you'll need to ensure that Django has permission to create
  82. and alter tables in the database you're using; if you plan to manually create
  83. the tables, you can simply grant Django ``SELECT``, ``INSERT``, ``UPDATE`` and
  84. ``DELETE`` permissions. After creating a database user with these
  85. permissions, you'll specify the details in your project's settings file,
  86. see :setting:`DATABASES` for details.
  87. If you're using Django's :doc:`testing framework</topics/testing/index>` to test
  88. database queries, Django will need permission to create a test database.
  89. .. _PostgreSQL: https://www.postgresql.org/
  90. .. _MySQL: https://www.mysql.com/
  91. .. _psycopg2: http://initd.org/psycopg/
  92. .. _SQLite: https://www.sqlite.org/
  93. .. _cx_Oracle: http://cx-oracle.sourceforge.net/
  94. .. _Oracle: http://www.oracle.com/
  95. .. _removing-old-versions-of-django:
  96. Remove any old versions of Django
  97. =================================
  98. If you are upgrading your installation of Django from a previous version,
  99. you will need to uninstall the old Django version before installing the
  100. new version.
  101. If you installed Django using pip_ or ``easy_install`` previously, installing
  102. with pip_ or ``easy_install`` again will automatically take care of the old
  103. version, so you don't need to do it yourself.
  104. If you previously installed Django using ``python setup.py install``,
  105. uninstalling is as simple as deleting the ``django`` directory from your Python
  106. ``site-packages``. To find the directory you need to remove, you can run the
  107. following at your shell prompt (not the interactive Python prompt):
  108. .. code-block:: console
  109. $ python -c "import django; print(django.__path__)"
  110. .. _install-django-code:
  111. Install the Django code
  112. =======================
  113. Installation instructions are slightly different depending on whether you're
  114. installing a distribution-specific package, downloading the latest official
  115. release, or fetching the latest development version.
  116. It's easy, no matter which way you choose.
  117. .. _installing-official-release:
  118. Installing an official release with ``pip``
  119. -------------------------------------------
  120. This is the recommended way to install Django.
  121. 1. Install pip_. The easiest is to use the `standalone pip installer`_. If your
  122. distribution already has ``pip`` installed, you might need to update it if
  123. it's outdated. If it's outdated, you'll know because installation won't
  124. work.
  125. 2. Take a look at virtualenv_ and virtualenvwrapper_. These tools provide
  126. isolated Python environments, which are more practical than installing
  127. packages systemwide. They also allow installing packages without
  128. administrator privileges. The :doc:`contributing tutorial
  129. </intro/contributing>` walks through how to create a virtualenv.
  130. 3. After you've created and activated a virtual environment, enter the command
  131. ``pip install Django`` at the shell prompt.
  132. .. _pip: https://pip.pypa.io/
  133. .. _virtualenv: https://virtualenv.pypa.io/
  134. .. _virtualenvwrapper: https://virtualenvwrapper.readthedocs.io/en/latest/
  135. .. _standalone pip installer: https://pip.pypa.io/en/latest/installing/#installing-with-get-pip-py
  136. .. _installing-distribution-package:
  137. Installing a distribution-specific package
  138. ------------------------------------------
  139. Check the :doc:`distribution specific notes </misc/distributions>` to see if
  140. your platform/distribution provides official Django packages/installers.
  141. Distribution-provided packages will typically allow for automatic installation
  142. of dependencies and easy upgrade paths; however, these packages will rarely
  143. contain the latest release of Django.
  144. .. _installing-development-version:
  145. Installing the development version
  146. ----------------------------------
  147. .. admonition:: Tracking Django development
  148. If you decide to use the latest development version of Django,
  149. you'll want to pay close attention to `the development timeline`_,
  150. and you'll want to keep an eye on the :ref:`release notes for the
  151. upcoming release <development_release_notes>`. This will help you stay
  152. on top of any new features you might want to use, as well as any changes
  153. you'll need to make to your code when updating your copy of Django.
  154. (For stable releases, any necessary changes are documented in the
  155. release notes.)
  156. .. _the development timeline: https://code.djangoproject.com/timeline
  157. If you'd like to be able to update your Django code occasionally with the
  158. latest bug fixes and improvements, follow these instructions:
  159. 1. Make sure that you have Git_ installed and that you can run its commands
  160. from a shell. (Enter ``git help`` at a shell prompt to test this.)
  161. 2. Check out Django's main development branch like so:
  162. .. code-block:: console
  163. $ git clone https://github.com/django/django.git
  164. This will create a directory ``django`` in your current directory.
  165. 3. Make sure that the Python interpreter can load Django's code. The most
  166. convenient way to do this is to use virtualenv_, virtualenvwrapper_, and
  167. pip_. The :doc:`contributing tutorial </intro/contributing>` walks through
  168. how to create a virtualenv.
  169. 4. After setting up and activating the virtualenv, run the following command:
  170. .. code-block:: console
  171. $ pip install -e django/
  172. This will make Django's code importable, and will also make the
  173. ``django-admin`` utility command available. In other words, you're all
  174. set!
  175. When you want to update your copy of the Django source code, just run the
  176. command ``git pull`` from within the ``django`` directory. When you do this,
  177. Git will automatically download any changes.
  178. .. _Git: http://git-scm.com/