I have several virtual hosts configured under the same apache instance on redhat:

  • apache-2.2.15
  • mod_wsgi-3.5 compiled with default system python-2.6

For every virtual host WSGIScriptAlias setting is pointed to the python file where the virtual environment is activated:

activate_this = '/path_to_the_virtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

Now, I'm planning to upgrade one of the projects to python-2.7, another one to python-3.x. I know that I can have different virtual environments, separate python sandboxes. So, everything is good on the python side.

The question is: is it possible to use different python versions for different apache virtual hosts under the same apache+mod_wsgi instance?

If not, what would be the best option to proceed?

There is a relevant WsgiPythonHome setting, but it is defined globally in the "server config" context, not per virtual host. Plus, mod_wsgi is compiled for the specific python version, so I'm not sure it can handle the case.

1 Answer 1


No it isn't possible. The mod_wsgi binary has to be compiled against one Python version only and only one instance of a compiled mod_wsgi module can be loaded into Apache at a time.

What you would need to do is setup Apache to proxy to a separate WSGI server listening on its own ports.

To use Apache/mod_wsgi as that backend server as well, you would want to investigate using mod_wsgi 4.1.X. See:

This newer version of mod_wsgi provides a way of installing mod_wsgi against multiple Python versions and running up an Apache instance for each using a provided script. The script takes over all the setup of the Apache configuration so you do not need to worry about it.

  • Glad to see you on StackExchange again! Thank you very much, this is exactly what I wanted to know.
    – alecxe
    May 31, 2014 at 7:25
  • Why is that? Is this a limitation of the mod_swgi implementation, or of Apache?
    – Jens
    Feb 16, 2015 at 14:51
  • It is an operating system limitation. You can't load two different versions of the Python library into the one process. Feb 16, 2015 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.