2005-07-15 23:21:18 +02:00
|
|
|
=====================
|
|
|
|
How to install Django
|
|
|
|
=====================
|
|
|
|
|
2005-07-15 23:51:05 +02:00
|
|
|
This document will get you up and running with Django.
|
|
|
|
|
2005-11-12 04:24:32 +01:00
|
|
|
Install Python
|
|
|
|
==============
|
|
|
|
|
2015-06-17 17:27:25 +02:00
|
|
|
Being a Python Web framework, Django requires Python. See
|
|
|
|
:ref:`faq-python-version-support` for details.
|
2005-11-12 04:24:32 +01:00
|
|
|
|
2014-12-19 16:25:57 +01:00
|
|
|
Get the latest version of Python at https://www.python.org/download/ or with
|
2013-12-30 18:15:49 +01:00
|
|
|
your operating system's package manager.
|
2005-11-12 04:24:32 +01:00
|
|
|
|
2008-08-26 17:52:21 +02:00
|
|
|
.. admonition:: Django on Jython
|
|
|
|
|
|
|
|
If you use Jython_ (a Python implementation for the Java platform), you'll
|
2010-08-19 21:27:44 +02:00
|
|
|
need to follow a few additional steps. See :doc:`/howto/jython` for details.
|
2008-08-26 17:52:21 +02:00
|
|
|
|
|
|
|
.. _jython: http://jython.org/
|
|
|
|
|
2012-03-02 05:27:46 +01:00
|
|
|
.. admonition:: Python on Windows
|
|
|
|
|
2014-03-19 19:38:12 +01:00
|
|
|
If you are just starting with Django and using Windows, you may find
|
|
|
|
:doc:`/howto/windows` useful.
|
2012-03-02 05:27:46 +01:00
|
|
|
|
2016-01-24 22:26:11 +01:00
|
|
|
Install Apache and ``mod_wsgi``
|
|
|
|
===============================
|
2005-07-15 23:51:05 +02:00
|
|
|
|
2010-08-28 04:40:57 +02:00
|
|
|
If you just want to experiment with Django, skip ahead to the next
|
2011-06-16 18:34:12 +02:00
|
|
|
section; Django includes a lightweight web server you can use for
|
2010-08-28 04:40:57 +02:00
|
|
|
testing, so you won't need to set up Apache until you're ready to
|
|
|
|
deploy Django in production.
|
|
|
|
|
2011-06-16 18:34:12 +02:00
|
|
|
If you want to use Django on a production site, use `Apache`_ with
|
2010-08-28 04:40:57 +02:00
|
|
|
`mod_wsgi`_. mod_wsgi can operate in one of two modes: an embedded
|
|
|
|
mode and a daemon mode. In embedded mode, mod_wsgi is similar to
|
|
|
|
mod_perl -- it embeds Python within Apache and loads Python code into
|
|
|
|
memory when the server starts. Code stays in memory throughout the
|
|
|
|
life of an Apache process, which leads to significant performance
|
|
|
|
gains over other server arrangements. In daemon mode, mod_wsgi spawns
|
|
|
|
an independent daemon process that handles requests. The daemon
|
2010-10-09 10:12:50 +02:00
|
|
|
process can run as a different user than the Web server, possibly
|
2010-08-28 04:40:57 +02:00
|
|
|
leading to improved security, and the daemon process can be restarted
|
2010-10-09 10:12:50 +02:00
|
|
|
without restarting the entire Apache Web server, possibly making
|
2010-08-28 04:40:57 +02:00
|
|
|
refreshing your codebase more seamless. Consult the mod_wsgi
|
|
|
|
documentation to determine which mode is right for your setup. Make
|
|
|
|
sure you have Apache installed, with the mod_wsgi module activated.
|
|
|
|
Django will work with any version of Apache that supports mod_wsgi.
|
|
|
|
|
2011-10-22 06:30:10 +02:00
|
|
|
See :doc:`How to use Django with mod_wsgi </howto/deployment/wsgi/modwsgi>`
|
2010-08-28 04:40:57 +02:00
|
|
|
for information on how to configure mod_wsgi once you have it
|
|
|
|
installed.
|
|
|
|
|
2011-09-04 23:17:30 +02:00
|
|
|
If you can't use mod_wsgi for some reason, fear not: Django supports many other
|
2012-07-22 16:54:47 +02:00
|
|
|
deployment options. One is :doc:`uWSGI </howto/deployment/wsgi/uwsgi>`; it works
|
2013-07-18 17:10:49 +02:00
|
|
|
very well with `nginx`_. Additionally, Django follows the WSGI spec
|
2014-08-11 13:34:48 +02:00
|
|
|
(:pep:`3333`), which allows it to run on a variety of server platforms.
|
2005-07-15 23:51:05 +02:00
|
|
|
|
2015-11-29 17:29:46 +01:00
|
|
|
.. _Apache: https://httpd.apache.org/
|
2012-06-28 10:49:07 +02:00
|
|
|
.. _nginx: http://nginx.org/
|
2015-09-03 23:23:08 +02:00
|
|
|
.. _mod_wsgi: http://www.modwsgi.org/
|
2005-07-15 23:51:05 +02:00
|
|
|
|
2008-08-24 00:25:40 +02:00
|
|
|
.. _database-installation:
|
|
|
|
|
2005-07-15 23:51:05 +02:00
|
|
|
Get your database running
|
|
|
|
=========================
|
|
|
|
|
2009-06-24 16:00:53 +02:00
|
|
|
If you plan to use Django's database API functionality, you'll need to make
|
|
|
|
sure a database server is running. Django supports many different database
|
|
|
|
servers and is officially supported with PostgreSQL_, MySQL_, Oracle_ and
|
2012-10-12 01:54:52 +02:00
|
|
|
SQLite_.
|
|
|
|
|
2012-10-16 01:54:37 +02:00
|
|
|
If you are developing a simple project or something you don't plan to deploy
|
|
|
|
in a production environment, SQLite is generally the simplest option as it
|
|
|
|
doesn't require running a separate server. However, SQLite has many differences
|
|
|
|
from other databases, so if you are working on something substantial, it's
|
|
|
|
recommended to develop with the same database as you plan on using in
|
|
|
|
production.
|
2005-07-15 23:51:05 +02:00
|
|
|
|
2013-12-19 00:48:21 +01:00
|
|
|
In addition to the officially supported databases, there are :ref:`backends
|
|
|
|
provided by 3rd parties <third-party-notes>` that allow you to use other
|
|
|
|
databases with Django.
|
2009-06-24 16:00:53 +02:00
|
|
|
|
|
|
|
In addition to a database backend, you'll need to make sure your Python
|
|
|
|
database bindings are installed.
|
2005-07-18 20:47:55 +02:00
|
|
|
|
2015-02-16 20:22:22 +01:00
|
|
|
* If you're using PostgreSQL, you'll need the `psycopg2`_ package. Refer to the
|
|
|
|
:ref:`PostgreSQL notes <postgresql-notes>` for further details.
|
2007-04-26 16:58:18 +02:00
|
|
|
|
2015-02-16 20:22:22 +01:00
|
|
|
* If you're using MySQL, you'll need a :ref:`DB API driver
|
|
|
|
<mysql-db-api-drivers>` like ``mysqlclient``. See :ref:`notes for the MySQL
|
|
|
|
backend <mysql-notes>` for details.
|
2007-02-26 22:39:09 +01:00
|
|
|
|
2013-10-07 12:40:41 +02:00
|
|
|
* If you're using SQLite you might want to read the :ref:`SQLite backend notes
|
|
|
|
<sqlite-notes>`.
|
|
|
|
|
2009-02-28 07:03:18 +01:00
|
|
|
* If you're using Oracle, you'll need a copy of cx_Oracle_, but please
|
2015-02-16 20:22:22 +01:00
|
|
|
read the :ref:`notes for the Oracle backend <oracle-notes>` for details
|
|
|
|
regarding supported versions of both Oracle and ``cx_Oracle``.
|
2007-06-23 16:16:00 +02:00
|
|
|
|
2009-06-24 16:00:53 +02:00
|
|
|
* If you're using an unofficial 3rd party backend, please consult the
|
|
|
|
documentation provided for any additional requirements.
|
|
|
|
|
2013-07-25 17:19:36 +02:00
|
|
|
If you plan to use Django's ``manage.py migrate`` command to automatically
|
2012-12-16 21:42:01 +01:00
|
|
|
create database tables for your models (after first installing Django and
|
|
|
|
creating a project), you'll need to ensure that Django has permission to create
|
|
|
|
and alter tables in the database you're using; if you plan to manually create
|
|
|
|
the tables, you can simply grant Django ``SELECT``, ``INSERT``, ``UPDATE`` and
|
2013-07-25 17:19:36 +02:00
|
|
|
``DELETE`` permissions. After creating a database user with these
|
2012-12-16 21:42:01 +01:00
|
|
|
permissions, you'll specify the details in your project's settings file,
|
|
|
|
see :setting:`DATABASES` for details.
|
2007-12-04 07:07:44 +01:00
|
|
|
|
2012-12-22 01:59:06 +01:00
|
|
|
If you're using Django's :doc:`testing framework</topics/testing/index>` to test
|
2012-12-12 00:43:37 +01:00
|
|
|
database queries, Django will need permission to create a test database.
|
2007-09-15 06:58:41 +02:00
|
|
|
|
2005-07-15 23:51:05 +02:00
|
|
|
.. _PostgreSQL: http://www.postgresql.org/
|
2015-11-29 17:29:46 +01:00
|
|
|
.. _MySQL: https://www.mysql.com/
|
2015-02-16 20:22:22 +01:00
|
|
|
.. _psycopg2: http://initd.org/psycopg/
|
2015-11-29 17:29:46 +01:00
|
|
|
.. _SQLite: https://www.sqlite.org/
|
2007-09-16 17:57:15 +02:00
|
|
|
.. _cx_Oracle: http://cx-oracle.sourceforge.net/
|
2007-06-26 14:53:33 +02:00
|
|
|
.. _Oracle: http://www.oracle.com/
|
2015-09-25 21:27:41 +02:00
|
|
|
|
2008-08-24 00:25:40 +02:00
|
|
|
.. _removing-old-versions-of-django:
|
2005-07-15 23:51:05 +02:00
|
|
|
|
2007-04-12 15:59:09 +02:00
|
|
|
Remove any old versions of Django
|
|
|
|
=================================
|
|
|
|
|
2007-05-11 11:51:07 +02:00
|
|
|
If you are upgrading your installation of Django from a previous version,
|
|
|
|
you will need to uninstall the old Django version before installing the
|
|
|
|
new version.
|
2007-04-12 15:59:09 +02:00
|
|
|
|
2012-05-22 01:28:58 +02:00
|
|
|
If you installed Django using pip_ or ``easy_install`` previously, installing
|
|
|
|
with pip_ or ``easy_install`` again will automatically take care of the old
|
|
|
|
version, so you don't need to do it yourself.
|
2007-04-12 15:59:09 +02:00
|
|
|
|
2012-05-22 01:28:58 +02:00
|
|
|
If you previously installed Django using ``python setup.py install``,
|
|
|
|
uninstalling is as simple as deleting the ``django`` directory from your Python
|
|
|
|
``site-packages``. To find the directory you need to remove, you can run the
|
|
|
|
following at your shell prompt (not the interactive Python prompt):
|
2007-04-12 15:59:09 +02:00
|
|
|
|
2015-02-19 04:19:21 +01:00
|
|
|
.. code-block:: console
|
2010-11-23 04:54:13 +01:00
|
|
|
|
2015-03-06 10:57:06 +01:00
|
|
|
$ python -c "import django; print(django.__path__)"
|
2007-04-12 15:59:09 +02:00
|
|
|
|
2008-08-26 17:52:21 +02:00
|
|
|
.. _install-django-code:
|
2007-04-12 15:59:09 +02:00
|
|
|
|
2005-07-15 23:51:05 +02:00
|
|
|
Install the Django code
|
|
|
|
=======================
|
|
|
|
|
2005-07-15 23:21:18 +02:00
|
|
|
Installation instructions are slightly different depending on whether you're
|
2008-08-24 00:25:40 +02:00
|
|
|
installing a distribution-specific package, downloading the latest official
|
2007-07-12 16:41:32 +02:00
|
|
|
release, or fetching the latest development version.
|
2005-07-15 23:21:18 +02:00
|
|
|
|
2007-07-12 16:41:32 +02:00
|
|
|
It's easy, no matter which way you choose.
|
2005-07-15 23:21:18 +02:00
|
|
|
|
2008-08-24 00:25:40 +02:00
|
|
|
.. _installing-official-release:
|
2007-02-27 00:23:01 +01:00
|
|
|
|
2012-03-03 10:11:54 +01:00
|
|
|
Installing an official release with ``pip``
|
2016-01-03 11:56:22 +01:00
|
|
|
-------------------------------------------
|
2012-03-03 10:11:54 +01:00
|
|
|
|
|
|
|
This is the recommended way to install Django.
|
|
|
|
|
|
|
|
1. Install pip_. The easiest is to use the `standalone pip installer`_. If your
|
2012-03-12 21:05:48 +01:00
|
|
|
distribution already has ``pip`` installed, you might need to update it if
|
2015-12-05 22:28:29 +01:00
|
|
|
it's outdated. If it's outdated, you'll know because installation won't
|
2016-01-24 10:06:01 +01:00
|
|
|
work.
|
2012-03-03 10:11:54 +01:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
2. Take a look at virtualenv_ and virtualenvwrapper_. These tools provide
|
|
|
|
isolated Python environments, which are more practical than installing
|
|
|
|
packages systemwide. They also allow installing packages without
|
|
|
|
administrator privileges. The :doc:`contributing tutorial
|
|
|
|
</intro/contributing>` walks through how to create a virtualenv on Python 3.
|
2012-03-03 10:11:54 +01:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
3. After you've created and activated a virtual environment, enter the command
|
|
|
|
``pip install Django`` at the shell prompt.
|
2012-03-03 10:11:54 +01:00
|
|
|
|
2015-08-08 13:56:37 +02:00
|
|
|
.. _pip: https://pip.pypa.io/
|
2012-03-03 10:11:54 +01:00
|
|
|
.. _virtualenv: http://www.virtualenv.org/
|
2016-04-28 16:09:57 +02:00
|
|
|
.. _virtualenvwrapper: https://virtualenvwrapper.readthedocs.io/en/latest/
|
2016-06-16 03:20:23 +02:00
|
|
|
.. _standalone pip installer: https://pip.pypa.io/en/latest/installing/#installing-with-get-pip-py
|
2012-03-03 10:11:54 +01:00
|
|
|
|
2015-02-03 22:35:28 +01:00
|
|
|
Installing a distribution-specific package
|
2016-01-03 11:56:22 +01:00
|
|
|
------------------------------------------
|
2015-02-03 22:35:28 +01:00
|
|
|
|
|
|
|
Check the :doc:`distribution specific notes </misc/distributions>` to see if
|
|
|
|
your platform/distribution provides official Django packages/installers.
|
|
|
|
Distribution-provided packages will typically allow for automatic installation
|
|
|
|
of dependencies and easy upgrade paths; however, these packages will rarely
|
|
|
|
contain the latest release of Django.
|
|
|
|
|
2008-08-24 00:25:40 +02:00
|
|
|
.. _installing-development-version:
|
|
|
|
|
2005-07-15 23:21:18 +02:00
|
|
|
Installing the development version
|
2016-01-03 11:56:22 +01:00
|
|
|
----------------------------------
|
2005-07-15 23:21:18 +02:00
|
|
|
|
2008-03-19 00:18:52 +01:00
|
|
|
.. admonition:: Tracking Django development
|
2009-04-01 03:36:44 +02:00
|
|
|
|
2008-03-19 00:18:52 +01:00
|
|
|
If you decide to use the latest development version of Django,
|
|
|
|
you'll want to pay close attention to `the development timeline`_,
|
2012-09-09 18:53:32 +02:00
|
|
|
and you'll want to keep an eye on the :ref:`release notes for the
|
|
|
|
upcoming release <development_release_notes>`. This will help you stay
|
|
|
|
on top of any new features you might want to use, as well as any changes
|
2008-03-25 05:42:21 +01:00
|
|
|
you'll need to make to your code when updating your copy of Django.
|
|
|
|
(For stable releases, any necessary changes are documented in the
|
|
|
|
release notes.)
|
2008-03-19 00:18:52 +01:00
|
|
|
|
2012-03-13 18:53:31 +01:00
|
|
|
.. _the development timeline: https://code.djangoproject.com/timeline
|
2008-03-19 00:18:52 +01:00
|
|
|
|
2006-10-17 00:38:18 +02:00
|
|
|
If you'd like to be able to update your Django code occasionally with the
|
|
|
|
latest bug fixes and improvements, follow these instructions:
|
|
|
|
|
2012-04-28 05:26:16 +02:00
|
|
|
1. Make sure that you have Git_ installed and that you can run its commands
|
|
|
|
from a shell. (Enter ``git help`` at a shell prompt to test this.)
|
2007-06-20 08:23:15 +02:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
2. Check out Django's main development branch like so:
|
2008-08-24 00:25:40 +02:00
|
|
|
|
2015-02-19 04:19:21 +01:00
|
|
|
.. code-block:: console
|
2005-07-15 23:52:16 +02:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
$ git clone git://github.com/django/django.git
|
2007-09-14 10:04:07 +02:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
This will create a directory ``django`` in your current directory.
|
2011-06-26 18:52:13 +02:00
|
|
|
|
2012-05-22 01:28:58 +02:00
|
|
|
3. Make sure that the Python interpreter can load Django's code. The most
|
2015-09-25 21:27:41 +02:00
|
|
|
convenient way to do this is to use virtualenv_, virtualenvwrapper_, and
|
|
|
|
pip_. The :doc:`contributing tutorial </intro/contributing>` walks through
|
|
|
|
how to create a virtualenv on Python 3.
|
2009-04-01 03:36:44 +02:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
4. After setting up and activating the virtualenv, run the following command:
|
2007-09-14 10:04:07 +02:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
.. code-block:: console
|
2005-07-15 23:52:16 +02:00
|
|
|
|
2015-09-25 21:27:41 +02:00
|
|
|
$ pip install -e django/
|
2006-10-17 00:38:18 +02:00
|
|
|
|
2012-05-22 01:28:58 +02:00
|
|
|
This will make Django's code importable, and will also make the
|
2014-07-26 13:21:52 +02:00
|
|
|
``django-admin`` utility command available. In other words, you're all
|
2012-05-22 01:28:58 +02:00
|
|
|
set!
|
2007-11-29 17:57:20 +01:00
|
|
|
|
2006-10-17 00:38:18 +02:00
|
|
|
When you want to update your copy of the Django source code, just run the
|
2015-09-25 21:27:41 +02:00
|
|
|
command ``git pull`` from within the ``django`` directory. When you do this,
|
|
|
|
Git will automatically download any changes.
|
2005-07-15 23:21:18 +02:00
|
|
|
|
2011-06-26 18:52:13 +02:00
|
|
|
.. _Git: http://git-scm.com/
|