views:

687

answers:

2

So I am trying to make Django running with mod-wsgi for the first time. I have configured Apache as shown in examples and I am pretty sure I did everything right.

I did not set the PYTHON_EGG_CACHE variable so it uses the default: /var/www/.python-eggs. I have created this directory and made it writeable for user www-data.

When I open the site it shows the output from 500.html template and here's what I get in log:

   ...
   File "/usr/local/.../parts/django/django/db/__init__.py", line 17, in load_backend
     return import_module('.base', 'django.db.backends.%s' % backend_name)
   File "/usr/local/.../parts/django/django/utils/importlib.py", line 35, in import_module
     __import__(name)
   File "/usr/local/.../parts/django/django/db/backends/postgresql_psycopg2/base.py", line 22, in <module>
     raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
 ImproperlyConfigured: Error loading psycopg2 module: cannot import name tz

Here's what I have in /var/www/.python-eggs/

# ls -la /var/www/.python-eggs/
total 12
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 .
drwxr-xr-x 5 root     root     4096 Jan 27 04:18 ..
drwxr-xr-x 3 www-data www-data 4096 Jan 27 04:19 psycopg2-2.0.13-py2.5-linux-i686.egg-tmp

# ls -la /var/www/.python-eggs/psycopg2-2.0.13-py2.5-linux-i686.egg-tmp/psycopg2/
total 368
drwxr-xr-x 2 www-data www-data   4096 Jan 27 04:19 .
drwxr-xr-x 3 www-data www-data   4096 Jan 27 04:19 ..
-rwxr-xr-x 1 www-data www-data 363318 Jan 22 03:44 _psycopg.so

The only file in psycopg2 egg directory is _psycopg.so. There's no tz.py file and I think this is the problem.

Please advice.

P.S., I use buildout and djangorecipe to deploy Django. I run buildout script with buildout user. Not sure if it makes sense though.

P.P.S, psycopg2 is installed correctly because I am able to run syncdb.

A: 

I would suggest that if you're able to import it from the command line, then somewhere up the path, the www-data user is being forbidden access to the egg path.

Keryn Knight
+1  A: 

Ok, I have found the solution. I have used the system python for buildout and it already had psycopg2 in site-packages. It seems there was some kind of conflict between psycopg2 in system site-packages and the one installed by buildout. I have set up a virtual python environment and used it for buildout. And this helped! No more import errors.

Andrey Fedoseev