1. Preparation¶
We’ll use Django Version 1.8. To get started we need to do a little preparation.
1.1. Python¶
Django is written completely in Python. Therefore Python needs to be installed first.
Note
Django 1.8 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 --version
:
$ python --version
Python 2.7.6
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 Python 3 part of the Django documentation.
If you’ve already got the right version of Python installed, you can skip ahead to Python Package Managers.
1.1.1. 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.
1.1.2. Mac OS X¶
Python comes pre-installed on Mac OS X. You can however use Homebrew to install your own copy of Python.
1.1.3. 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 %PATH%
. In the examples, we’ll assume
that your Python is installed in C:\Python27\
.
1.1.3.1. Windows 7¶
- , then right click on
- Now click the context menu option Properties
- Next, in the window that just opened, click on the Advanced System Settings
- A further window will open, click the Environment Variables
- Under System Variables, select the
PATH
- Now click on Edit and add the required directory:
;C:\Python27\;C:\Python27\Scripts;
. (The semi-colon at the beginning is required!) - Now close the windows Environment Variables and System Properties by clicking on OK.
1.1.3.2. Windows XP¶
- Click on the Environment Variables, then a new window
will open. Under “System Variables” select
Path
- Now click on Edit and add the required directory:
;C:\Python27\;C:\Python27\Scripts;
. (The semi-colon at the beginning is required!) - Now close the windows Environment Variables and System Properties by clicking on OK.
1.2. Python Package Manager¶
Python has its own 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. pip was originally written as an improvement of easy_install.
To decide which installation procedure is right for you check again your Python version:
$ python --version
Python 2.7.6
1.2.1. 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 ensurepip to install or upgrade 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
1.2.2. 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 pip can be installed with the help from a bootstrap script. If curl is installed, you can use it to download 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 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 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.
1.2.3. Test pip¶
After a successful upgrade or installation, you can test pip as follows:
$ pip --version
pip 7.0.1 from /Users/keimlink/.virtualenvs/django-marcador/lib/python2.7/site-packages (python 2.7)