Notes for myself so I can do this again someday… (UPDATE: I had to refresh the links at the bottom of this article to the latest version of Django. Good luck.)
Let’s say we are working on a Django project called applesauce, for lack of a better name. We start by creating a directory for this project:
cd ~
mkdir applesauce
cd applesauce
We use pip to install python packages, so we must install it first:
sudo apt-get install python-pip python-setuptools
We use virtualenv to manage our python environment to make sure we don’t go too crazy. We can use pip to install it:
sudo pip install virtualenv
virtualenv has this idea of using a directory to store its settings, so let’s make one for it, and use it as a new virtual environment:
mkdir applesauce-virtualenv
virtualenv applesauce-virtualenv
The –no-site-packages is the default now, so we don’t include it here (you could, but it’s deprecated). This helps keep things sane.
virtualenv creates a shell script for you to source that sets up the necessary environment variables. You will need to source this file every time you want to work on this project:
source applesauce-virtualenv/bin/activate
You should see that your shell prompt has changed, and now has “(applesauce-virtualenv)” at the front of the prompt. This lets you know that you have already “logged in” to your virtualenv.
Now, let’s install some of the packages required to work with Django. We start with the non-python system-wide packages and libraries:
sudo apt-get install libxml2-dev libxslt1-dev python2.7-dev libpng12-dev libfreetype6-dev build-essential python-dev
Then, make sure that you are in your virtual environment and install these python things using pip. Since we’re installing these packages into the virtualenv we don’t need to use sudo.
pip install django django-debug-toolbar south httplib2 lxml
If you have any modules/packages that you want to be able to use in your Django project, you can copy them into applesauce-virtualenv/lib/python2.7/site-packages/
To verify that Django can be seen by Python, type python from your shell. Then at the Python prompt, try to import Django:
>>> import django
>>> print django.get_version()
1.4.1
Now, you can start working with Django. You might want to start with the official tutorial, Writing your first Django app.
(Some information taken from the Django Quick install guide.)