Standalone Python project/installation

Published 08-16-2011 00:00:00

Let’s take an example of installing Django without using Debian apt command. We will use virtualenv to make a self-contained python directory.

First create your installation directory:

$ mkdir -p project/django
$ cd project/django

Get the virtualenv tool:

$ wget --no-check-certificate 'https://raw.github.com/pypa/virtualenv/develop/virtualenv.py'

Create the virtual environment:

$ python virtualenv.py --no-site-packages --distribute python_django_env

Note interesting parameters::

--no-site-packages    Don't give access to the global site-packages dir to
                      the virtual environment
--distribute          Use Distribute instead of Setuptools. Set environ
                      variable VIRTUALENV_USE_DISTRIBUTE to make it the
                      default

This will create a brand new Python environment (--no-site-packages) using Distribute. Distribute seems to be the new prefered packaging system instead of Setuptools.

Make the environment relocatable:

--relocatable         Make an EXISTING virtualenv environment relocatable.
                      This fixes up scripts and makes all .pth files
                      relative

$ python virtualenv.py --relocatable python_django_env

Next, you need to use your new Python environment:

$ . python_django_env/bin/activate

Install Django

$ pip install django

You can now use django-admin:

$ django-admin.py --help
Usage: django-admin.py subcommand [options] [args]

Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=all output
  --settings=SETTINGS   The Python path to a settings module, e.g.
[ ... ]