17

I'm trying to get WSGI to run with a virtualenv setup. I have the virtualenv all working right:

(virtualenv)dev:/var/www/app$ which python
/var/www/virtualenv/bin/python
(virtualenv)dev:/var/www/app$ python
Python 2.6.1 (r261:67515, Dec  5 2008, 22:09:34)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib
>>>

And in my httpd.conf, I have the following, as described here:

WSGIPythonHome /var/www/virtualenv
WSGIPythonPath /var/www/virtualenv/lib/python2.6/site-packages

But when I try to load the app via apache, i get the following error:

[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1] mod_wsgi (pid=15026): Exception occurred processing WSGI script '/var/www/app/wsgi.py'.
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1]   File "/var/www/app/wsgi.py", line 29, in <module>
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1]     import importlib
[Wed Dec 28 12:28:15 2011] [error] [client 127.0.0.1] ImportError: No module named importlib

What am I missing? How do even debug this kind of problem?

zigdon
  • 14,573
  • 6
  • 35
  • 54
  • `importlib` is mostly a Python 3 thing (though a *very* small subset of it is available in 2.7). It's not present in 2.6 at all. – Amber Dec 28 '11 at 20:32
  • 1
    Alright, but if it's working from the commandline, shouldn't it work from Apache? – zigdon Dec 28 '11 at 20:42

1 Answers1

20

Your mod_wsgi is likely compiled against a different Python version than you are trying to force it to use. For example, you can not use mod_wsgi compiled against Python 2.4 with a virtual environment constructed using Python 2.6.

Validate what version of Python mod_wsgi was built for in the first place.

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • Yeah, there's an entry in the logs where it's saying it's complied against the wrong version. Alright - I try to build it with `--use-python=/var/www/virtualenv/bin/python`, but it still gives the same warning? Is there a different flag I should use? – zigdon Dec 29 '11 at 01:49
  • 2
    The option is --with-python, not --use-python. Use ldd on the resulting mod_wsgi.so to verify which Python shared library version is being used. Read through the document http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation – Graham Dumpleton Dec 29 '11 at 04:27
  • @GrahamDumpleton, I am curious... is there a way to run multiple mod_wsgi instances (that have been compiled against different versions of python) under the same Apache process? – Mike Pennington Jan 03 '12 at 12:31
  • 2
    No. You need separate Apache instances with two different mod_wsgi.so modules each against different Python version. To be able to handle two different Python versions would need a lot of restructuring of mod_wsgi code and to make it simpler, the dropping of support for embedded mode. – Graham Dumpleton Jan 03 '12 at 21:51