Question

pythonbrew isn't getting picked up by by mod_wsgi file, config follows:

import os
import sys
import site

site.addsitedir('/home/bharal/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages')
sys.path.append ('/home/bharal/public_html/dumpstown')

os.environ['DJANGO_SETTINGS_MODULE'] = 'dumpstown.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

and the pythonbrew version of python i want to use is situated here:

/home/bharal/.pythonbrew/pythons/Python-2.7.2/lib/python2.7/site-packages

and my pythonbrew install is here:

/home/bharal/.pythonbrew/

How do i tell mod_wsgi to use this version (2.7.2) and not the default python version that shipped with ubuntu (2.6)?

When i run my server, i get errors like so:

[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] mod_wsgi (pid=18694): Exception occurred processing WSGI script '/home/bharal/public_html/dumpstown/dumpstown/apache/dumpstown.wsgi'.
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]     self.load_middleware()
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 276, in __getattr__
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]     self._setup()
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 42, in _setup
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]     self._wrapped = Settings(settings_module)
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 89, in __init__
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Wed Jul 04 02:17:27 2012] [error] [client 127.0.0.1] ImportError: Could not import settings 'dumpstown.settings' (Is it on sys.path?): No module named gravatar.templatetags

as you can see from the logs, the server is still looking at python 2.6!! Why? I've kicked off pythonbrew so when i type in python i can see the version is 2.7.2, and all the settings and packages i need are importable!

UPDATE as indicated in the answer below, the mod_wsgi doesn't care which python i tell it to use - in fact, i cannot tell it to use any particular python. The only way to do so is to download an uncompiled wsgi file, compile with the particular python version i want, and use the compiled wsgi.

See my other question Error: Command failed with rc=65536 python and mod_wsgi for some of the steps and links to tutes if you like. In the end i didn't compile against 2.7 (my 2.6 was fine and it was too hard to get the pythonbrew compile working)

Was it helpful?

Solution

That particular error has nothing to do with the version of Python used. Use:

sys.path.append ('/home/bharal/public_html') sys.path.append ('/home/bharal/public_html/dumpstown')

To get mod_wsgi to use a specific version, compile it from source code against that version or find a binary package for mod_wsgi compiled against the correct version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top