Multiple python versions under apache+mod_wsgi

19,441

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.

Share:
19,441

Related videos on Youtube

alecxe
Author by

alecxe

"I am a soldier, at war with entropy itself" I am a Software Developer and generalist who is in love with the Python language and community. I greatly value clean and maintainable code, great software, but I know when I need to be a perfectionist and when it stands in a way of product delivery. I like to break things, to find new ways to break things, to solve hard problems, to put things under test and stress, and to have my mind blown by an interesting question. Some of my interests: Learning, Productivity, AI, Space Exploration, Internet of Things. "If you change the way you look at things, the things you look at change." - Wayne Dyer If you are looking for a different way to say "Thank you": Amazon wish list Pragmatic wish list Today I left my phone at home And went down to the sea. The sand was soft, the ocean glass, But I was still just me. Then pelicans in threes and fours, Glided by like dinosaurs, An otter basked upon its back, And dived to find another snack. The sun corpuscular and bright, Cast down a piercing shaft, And conjured an inspiring sight On glinting, bobbing craft. Two mermaids rose up from the reef, Out of the breaking waves. Their siren song was opium grief, Their faces from the grave. The mermaids asked a princely kiss To free them from their spell. I said to try a poet’s bliss. They shrugged and bid farewell. The sun grew dark and sinister, In unscheduled eclipse. As two eight-headed aliens Descended in their ships. They said the World was nice enough But didn’t like our star. And asked the way to Betelgeuse, If it wouldn’t be too far. Two whales breached far out to sea, And flew up to the sky, The crowd was busy frolicking, And didn’t ask me why. Today I left my phone at home, On the worst day, you’ll agree. If only I had pictures, If only you could see. Not everything was really there, I’m happy to confess, But I still have the memories, Worth more than tweets and stress. Today I left my phone at home, I had no shakes or sorrow. If that is what my mind can do, It stays at home tomorrow. Gavin Miller

Updated on September 18, 2022

Comments

  • alecxe
    alecxe almost 2 years

    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.

  • Jens
    Jens over 9 years
    Why is that? Is this a limitation of the mod_swgi implementation, or of Apache?
  • Graham Dumpleton
    Graham Dumpleton over 9 years
    It is an operating system limitation. You can't load two different versions of the Python library into the one process.