Installing Zoook on Ubuntu – Part II: Python and Django

1 Install Python

The default Python interpreter on Ubuntu 11.10 is 2.7.2. To verify that this is the version on your system execute:

$ python

This should return something like the following:

Find out the version of your Python installation.

The message indicates that the version 2.7.2 is installed.

To exit the Python interpreter execute a

>>> quit()

In the rare case that there is no Python on your system, install it via

$ sudo apt-get install python

2 Install Django

Install all dependencies needed by Django:

$ sudo apt-get install python-dev python-psycopg2

You can install Django in three different ways:

  1. via the package management system of your distribution,
  2. fetching the latest stable version from the website, or
  3. download the development version from their repositories.

2.1 Installation via the package management system

The installation via the package management system is as simple as

$ sudo apt-get install python-django

2.2 Installing the last stable version from the website

Surf to the download section of the Django site and check for the latest stable version. That was 1.3.1 as of this writing (8th of February 2012).

$ cd ~
$ tar xvzf Django-1.3.1.tar.gz
$ mv Django-1.3.1 django-src

This way you’ll find the source code in the directory ~/django-src. The next step is to pass this information to Python. Locate the site-packages of your Python installation:

$ python -c "from distutils.sysconfig import get_python_lib; 
 print get_python_lib()"

This should return something like the following:

Locate the site-packages of your Python installation.

which indicates that your site-package directory is /usr/lib/python2.7/dist-packages. In this directory you’ll have to add the route to the Django sources:

$ echo '/home/roberto/django-src' | sudo tee -a 

This creates the file /usr/lib/python2.7/dist-packages/django.pth with the path to your Django installation.

To make a live a bit more comfortable, create a symbolic link to

$ sudo ln -s /home/roberto/django-src/django/bin/ 

This way you can use in every place of the file system instead of executing the script by its absolute path ~/django-src/django/bin/

3 Verify the installation

Check that Python can find the Django modules:

$ python
>>> import django
>>> print django.get_version()

This should return something like:

Check that Python finds Django.

This indicates that Python detected Django in its 1.3.1 version.

3.1 Create a Django test project

We are going to create a Django test page in order to verify that everything is working fine. At first create a new directory for this:

$ mkdir ~/django-projects
$ cd ~/django-projects

In this case the directory is located in the home directory of the user and has the name django-projects. Now, create a test project in this category:

$ startproject testdjango

Change to the directory of the project and start the Django server:

$ cd testdjango
$ python runserver

This should return something like:

Successfully started Django server.

The server started up correctly and is waiting for connections on port 8000 ( When navigating your browser to this direction you should see a site like this:

Djangos start page.

Now, we could create a database in PostgreSQL and verify the connection with the project. But, given the aim of this article (install Zoook) we’re going into the details of the database access when configuring Zoook.