Since Django is just Python, theoretically it just a matter of putting your Django’s project and apps module under PYTHONPATH. Easy as it sound. But Python packaging currently in a state of mess, at least that’s the way I see it.
First we have the standard (which come in std lib) distutils module to help developers package their modules for easy distribution. Basically you put your modules inside a zip or tarball with one file named setup.py that contain the installation routines. So to install a Python modules package with distutils you would:
$ wget http://some.site.com/tarball/mypython-modules-1.2.tar.gz
$ tar xzf mypython-modules-1.2.tar.gz
$ ls
mypython setup.py README
$ python setup.py install
The module would then be installed under your standard site-packages directory and should be ready to import.
Then some people realize that this has some shortcoming. What happen when you want to install the new mypython-modules-1.3 when it comes out but still keeping the old one ? Running setup.py install would just override the old one because no versioning information is being kept by the packaging system once you install it into your site-packages. So people come with setuptools package as an extension to distutils. Basically the idea is to keep some meta information about the packages being installed alongside the modules in site-packages directory so that different version can installed without overwriting each other. Sound’s great but the end result is a really weird site-packages directory you would have.
Consider the site-packages installed with just the plain disutils:-
$ ls /home/kamal/python/lib/python2.5/site-packages
beaker docutils glasshammer jinja mako pygments sphinx sqlalchemy werkzeug
and with setuptools:-
$ ls /home/kamal/python/lib/python2.5/site-packages
Beaker-1.3.1-py2.5.egg Pygments-1.0-py2.5.egg
docutils-0.5-py2.5.egg setuptools-0.6c8-py2.5.egg
easy-install.pth setuptools.pth
Glashammer-0.2.1dev_20090706-py2.5.egg Sphinx-0.6.2-py2.5.egg
Jinja2-2.1.1-py2.5-linux-i686.egg SQLAlchemy-0.5.4p2-py2.5.egg
Mako-0.2.4-py2.5.egg Werkzeug-0.5-py2.5.egg
setuptools make use of Python ability to read from zip files and put all the modules inside single zip archive, known as egg. To be able to install multiple versions together, it need to store some information (path actually) inside .pth files.
I get started into Python when there’s already tools called virtualenv from Ian Bicking that let you create a local isolated Python environment specifically for your project without the need to interfere with the global system Python. So in practice, I never had the requirements to install multiple version of the same module inside my site-packages. I would just create another isolated environment if I really need to do that (which most of the time never happened).
There’s still part of setuptools that I found useful, and I’m using it in my daily Python development. The easy_install script. What it does is, given a package name, it would go to PyPI (Python Package Index) or it’s mirror hunting for the specified package and if exists, download and install it to the appropriate place in your system. The only problem, it would install that package as a Python egg, creating the mess I described before.
The problem I have with this eggs is, when deploying through mod_wsgi, I have to add all the eggs directory (mean all the installed module) into PYTHONPATH since mod_wsgi unable to find the module inside an egg.