UPDATE: I’ve rewrited the post since the instructions are much easier than I did put here (and more secure)
You will probably say: “Hey!, what’s in your mind to need django 1.3, it has been released just a week ago!”. The answer is: long-term development. Currently I’m working on e-cidadania, an e-democracy tool designed for participative processes. The development will take some time, and we’ve just started. It’s better to update everything now than later, but to the point, installing django 1.3 in dreamhost.
NOTE: I assume you know how to install a django project in DH. If not, please see this wiki
Let’s start.
STEP 1: CREATE A VIRTUALENV
You can create a virtualenv with the system-wide python installation (currently 2.5.2) or install your own python interpreter if you need it. We will use the system-wide python for convenience, since it’s still supported by django 1.3.
This part is extracted from here
NOTE: These commands must be typed at your home directory
$ wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.5.2.tar.gz
$ tar xzf virtualenv-1.5.2.tar.gz
$ python virtualenv-1.5.2/virtualenv.py $HOME/env |
This will create a directory called “env” with all the stuff you need to work. Let’s do this virtual environment our default.
STEP 2: STABLISH THE VIRTUALENV PYTHON AS DEFAULT
The following instructions about stablishing the virtual python as default only work at shell level. For passenger the system-wide python is the default.
On ~/.bash_profile write:
export PATH=$PATH:$HOME/env/bin |
This will stablish the directory ~/env/bin (where our virtual python is) before the system-wide python. To work right now without logging in again, we can do:
That will make the executables in ~/env/bin available for using right now, and between them, it’s easy_install, properly configured to install any python module locally without problem.
STEP 3: INSTALL DJANGO 1.3 AND ANY OTHER PACKAGES
Let’s install django 1.3 and some common python packages needed in almost every project:
For the moment we will install just django, because the rest of python packages are provided by the DH server. If you need non standard modules (p.e. python-dateutil) or other version of an already provided package, you must install them after django.
If you try to execute some django project right now you’ll see that the system-wide installation of django is the preferred. Let’s change that.
STEP 4: CONFIGURING PASSENGER_WSGI.PY
In our passenger_wsgi.py we must modify the PYTHONPATH, let’s do it:
import sys, os
# Python has no prepend function, so we must do an insert. We insert the key directories
# BEFORE ANYTHING, so the python installation sees them before the system-wide libraries.
sys.path.insert(0,'/home/USERNAME/env/bin')
sys.path.insert(0,'/home/USERNAME/env/lib/python2.5/site-packages/Django-1.3-py2.5.egg')
sys.path.insert(0,'/home/USERNAME/env/lib/python2.5/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = "YOURPROJECT.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler() |
Remember that if any of your modules fails, python will not fall back to the system-wide installation. Once a module is loaded, python does not seek another. Also, if you installed another package apart from django, you must do an insert including it.
That’s it! Now when you receive a visitor, Passenger will load you desired django version and packages.