Django 1.5 on Debian Squeeze

Published: by Creative Commons Licence

Time to read: 4 minutes

Debian Squeeze has packages for Python 3.1 but Django 1.5 requires Python 3.2. In this article I will describe how to set up Django 1.5 on Debian Squeeze and Apache by using Python 3.3.2 and the Apache module mod-wsgi compiled from sources.


First create the required directories.

mkdir -p /opt/python
mkdir -p /opt/mod-wsgi
chmod 755 /opt/python

Then download and unpack Python 3.3.

cd /opt/python
tar xvzf Python-3.3.2.tgz
ln -s Python-3.3.2 current
cd current
mkdir src
mv * src

And the same for mod-wsgi

cd /opt/mod-wsgi
tar xvzf mod-wsgi_3.4.orig.tar.gz
ln -s mod_wsgi-3.4 current
cd current
mkdir src
mv * src

I use the current links only to make it easier to switch between versions. Of course, you should go straight to download the latest version.

If you have Python 3.1 and the corresponding mod-wsgi installed from the Debian Squeeze package manager, you should uninstall both first. Anyway - it makes sense to install them first, because then you get the config-scripts for mod-wsgi for the Apache webserver.

aptitude install libapache2-mod-wsgi-py3
aptitude remove libapache2-mod-wsgi-py3


First I compile Python 3.3

cd /opt/python/current/src
./configure --prefix /opt/python/Python-3.3.2 --enable-shared
make && make install

--prefix specifies the target directory for the installation. --enable-shared indicates that Python 3.3 is built with shared libraries. This is important because it is needed to build mod-wsgi. If configure or make error messages raises about missing dependencies, you have to install them as -dev packages using Debian package manager.

If you now start Python 3.3, you will receive a Error message.

./python3: error while loading shared libraries: cannot open shared object file: No such file or directory

This occurs because the generated shared library libpython3.3m is assigned to the system is not yet known. So make it known.

cd /etc/
echo "/opt/python/current/lib" >>python.conf

The created file does not have to be python.conf. ldconfig makes the content of the new file known to the system and now Python 3 starts as well.

ln -s /opt/python/current/bin/python3 /usr/bin/python3
Python 3.3.2 (default, Aug 17 2013, 19:38:58) 
[GCC 4.4.5] on linux
Type "help", "copyright", "credits" or "license" for more information.

Pyhton 3 is up and ready. Now use the created shared library to build the Apache modules mod-wsgi.

cd /opt/mod-wsgi/current/src
./configure --prefix /opt/mod-wsgi/mod_wsgi-3.4 --with-python=/opt/python/current/bin/python3
make && make install

When you called make the error message /usr/bin/ld: cannot find -lpython3.3 will raise. In fact, the created file is called /opt/python/current/lib/ So adjust the Makefile line starting with LDLIBS. Now it finds the shared library and can bind it.

LDLIBS = -lpython3.3m -lpthread -ldl -lutil -lm

Although shared libraries begin with the prefix lib, you don't write it. Same for the file extension.

make && make install


Libraries have been installed in:

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   add LIBDIR to the `LD_LIBRARY_PATH' environment variable
 during execution
   add LIBDIR to the `LD_RUN_PATH' environment variable
 during linking
   use the `-Wl,-rpath -Wl,LIBDIR' left flag
   have your system administrator add LIBDIR to `/etc/'

See any operating system documentation about shared libraries for
more information, search as the ld(1) and manual pages.
chmod 644 /usr/lib/apache2/modules/

make install has already included the compiled file in the correct directory to /usr/lib/apache2/modules/. Apache is ready to go.

By uninstalling the Debian package from mod-wsgi Apache has kept its config files, but they are no longer active. I reactivated them through symbolic links.

cd /etc/apache2/mods-enabled
ln -s ../mods-available/wsgi-load wsgi.load
ln -s ../mods-available/wsgi-conf wsgi.conf
/etc/init.d/apache2 reload


The work is almpst done. Here are a few more Additional information.

In an Apache virtual host, I used the command WSGIScriptAlias /wsgi /home/wsgitest/wsgi the directory in which Apache executes Python scripts. I did not create other configurations for a first test. The installation of the Django framework:

mkdir /tmp/off
cd /tmp/off
tar xvzf Django-1.5.2.tar.gz
cd Django-1.5.2.tar.gz
python3 install