*********** Preparation *********** We'll use Django Version |djangoversion|. To get started we need to do a little preparation. .. index:: Install Python Python ====== Django is written completely in `Python `_. Therefore Python needs to be installed first. .. note:: Django |djangoversion| supports Python from version 2.7. If you have an older version of Python, you should update it. Django supports Python 3 since version 1.5. You can find out which version of Python you're running by using the command line option :option:`--version`: .. command-output:: python --version .. note:: If you are using Python 3 please make sure you have Python 3.3.2 or greater installed. Otherwise there will be problems. Also consider adding the following future-import on top of every Python file you are going to edit to ensure Python 2 and 3 compatibility: :: from __future__ import unicode_literals This way all regular strings will be unicode string literals. If you want to learn more read the :djangodocs:`Python 3 ` part of the Django documentation. If you've already got the right version of Python installed, you can skip ahead to :ref:`Python Package Managers `. Linux ----- Many Linux distributions come with Python already installed. If you haven't got a version of Python installed, you can normally use your package manager to download and install it. Alternatively, you can get the `Python Sources `_ from the website and compile it yourself. Mac OS X -------- Python comes pre-installed on Mac OS X. You can however use `Homebrew `_ to install your own copy of Python. Windows ------- Download the `Installer `_ from the Python Website and install it. So that Python works under Windows as expected, you need to change the environment variable :envvar:`%PATH%`. In the examples, we'll assume that your Python is installed in :file:`C:\\Python27\\`. Windows 7 ^^^^^^^^^ #. :menuselection:`Start`, then right click on :menuselection:`Computer` #. Now click the context menu option :guilabel:`Properties` #. Next, in the window that just opened, click on the :guilabel:`Advanced System Settings` #. A further window will open, click the :guilabel:`Environment Variables` #. Under `System Variables`, select the :option:`PATH` #. Now click on :guilabel:`Edit` and add the required directory: ``;C:\Python27\;C:\Python27\Scripts;``. (The semi-colon at the beginning is required!) #. Now close the windows :guilabel:`Environment Variables` and :guilabel:`System Properties` by clicking on `OK`. Windows XP ^^^^^^^^^^ #. :menuselection:`Start --> Control Panel --> System --> Advanced` #. Click on the :guilabel:`Environment Variables`, then a new window will open. Under "System Variables" select :option:`Path` #. Now click on :guilabel:`Edit` and add the required directory: ``;C:\Python27\;C:\Python27\Scripts;``. (The semi-colon at the beginning is required!) #. Now close the windows :guilabel:`Environment Variables` and :guilabel:`System Properties` by clicking on `OK`. .. index:: Install Python Package Manager .. _python-package-manager: Python Package Manager ====================== .. index:: pip Python has its own :pythondocs:`package system ` to manage distribution and installation of Python packages. Because we will need to install several packages, we must first make sure the package manager `pip `_ is installed. :program:`pip` was originally written as an improvement of :program:`easy_install`. To decide which installation procedure is right for you check again your Python version: .. command-output:: python --version Python 3.4 and Python 2.7.9 --------------------------- If you have Python 3.4 or Python 2.7.9 (or newer) installed you can use :pythondocs:`ensurepip ` to install or upgrade :program:`pip`: :: $ python -m ensurepip --upgrade If your Python version is too old you will simply see an error message like that: :: $ python -m ensurepip --upgrade /usr/bin/python: No module named ensurepip Python 3.3 and Python 2 ----------------------- If you have Python 3.3 or Python 2 with a version lower than 2.7.9 installed, your Python installation does not contain the module `ensurepip`. In this case :program:`pip` can be installed with the help from a `bootstrap script `_. If :program:`curl` is installed, you can use it to download :program:`pip` at the command line. Otherwise just use the browser. :: $ curl -O https://bootstrap.pypa.io/get-pip.py When the bootstrap script has been downloaded execute it to install :program:`pip`: :: $ python get-pip.py .. note:: Under Linux and Mac OS X root privileges may be required. In this case use: :: $ sudo python get-pip.py .. note:: If you have problems running :file:`get-pip.py` because of the configuration of your internet connection please have a look the `pip installation documentation `_. You can delete the bootstrap script when the installation has been finished. Test pip -------- After a successful upgrade or installation, you can test :program:`pip` as follows: .. command-output:: pip --version