views:

162

answers:

1

I would like to run a Django project on a server using virtualenv in Apache using mod_python. Now I know that the recommended apache module to use is mod_wsgi, but I don't want to install that for now.

The default python installation on the server is python2.4, which is used by some other website on the server. Because my project was built on python2.6 I installed it next to python2.4 in /usr/local/ using 'make altinstall'. I've used this website to setup my apache conf file: http://mydjangoblog.com/2009/03/30/django-mod_python-and-virtualenv/.

My question is: is there a way to specify that it (mod_python probably) should use python2.6 instead of python2.4? If there is no way to run 2 python versions in one apache using mod_python, would it be possible using mod_wsgi? Or would it be possible in one apache installation with the other site using mod_python and me using mod_wsgi?

+1  A: 

No, you cannot do this. mod_python is pre-compiled with a particular Python version. If you wanted to change that version, you'd have to re-compile mod_python - and if you're doing that, you might as well install mod_wsgi.

It is possible with mod_wsgi, as that doesn't embed an interpreter into Apache itself, so it doesn't care what version you use. It's quite easy to get virtualenv working with mod_wsgi - you just need to activate the virtualenv inside your .wsgi script:

activate_this = os.path.join(path_to_my_site, "bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
Daniel Roseman
+1 for mod_wsgi. Also checkout http://code.google.com/p/modwsgi/wiki/VirtualEnvironments I found it quite detailed and useful.
Manoj Govindan
Sorry, your advice is wrong about mod_wsgi. In mod_wsgi it does still embed an interpreter into Apache and it is still bound to a specific Python version. You cannot just go using virtual environments to have mod_wsgi refer to a different Python version. FWIW, you also cannot use mod_python and mod_wsgi at the same time where each uses a different Python version.
Graham Dumpleton
@Graham Dumpleton: Thanks for your reply. If what you're saying is the case does that mean I'll have to run 2 versions of apache in which each can use a different python version?
Heyl1
Yes, if you are talking about different Python versions, then need more than one Apache. Apache/mod_wsgi virtual environments are only of use for having different sets of modules against the same version of Python.
Graham Dumpleton