My django application loaded in Apache/mod_wsgi cannot find my external packages even though I specified it in sys.path?
The setup is as follows:
a) the external packages are in /var/www/site/my/python/config
b) the django website (with the settings.py file) is in /var/www/site/domain
c) the wsgi configuration file is:
import os, sys
sys.stdout = sys.stderr
# Add the virtual Python environment site-packages directory to the path
import site
site.addsitedir('/var/www/virtualenv/lib/python2.6/site-packages')
# Avoid ``[Errno 13] Permission denied: '/var/www/.python-eggs'`` messages
os.environ['PYTHON_EGG_CACHE'] = '/var/www/egg-cache'
# Add project directory to PYTHONPATH
sys.path.append('/var/www/site') # <---- THIS SHOULD FIND EXTERNAL PACKAGES?
os.environ['DJANGO_SETTINGS_MODULE'] = 'domain.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
d) the settings.py file starts with the following:
print "prior to import"
from my.python.config import ConfigParser # <---- THIS EXIST AS INDICATED IN a), but fails!
print after to import"
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', '[email protected]'),
)
MANAGERS = ADMINS
....
The error I'm getting is:
prior to import
mod_wsgi (pid=3465): Exception occurred processing WSGI script '/var/www/mod_wsgi/django.wsgi'.
Traceback (most recent call last):
File "/var/www/virtualenv/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
self.load_middleware()
File "/var/www/virtualenv/lib/python2.6/site-packages/django/core/handlers/base.py", line 39, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/var/www/virtualenv/lib/python2.6/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/var/www/virtualenv/lib/python2.6/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/var/www/virtualenv/lib/python2.6/site-packages/django/conf/__init__.py", line 89, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'domain.settings' (Is it on sys.path?): No module named python.config
You can see that the settings.py file is attempted loaded as "prior to import" is printed, but the code failes on importing "my.python.config.ConfigParser". It seems to detect it as python.config instead though?
Any clues?
I have been tearing my hair out all day. Everything however works both in eclipse environment and by directly invoking 'django-admin.py runserver 80' after setting the python path and the django environment variables. I also verified that the python path is in sys.path.
I ran out of ideas, so ANY help would be much appreciated!
Add at start of settings.py:
import my
print my.__file__
Validate that the path printed out is for the 'my' package you expect.
In other words, it could be picking up a different 'my' package because of such a package existing in multiple locations and the order of sys.path being wrong.
Also make sure you go read:
http://code.google.com/p/modwsgi/wiki/VirtualEnvironments
which talks about sys.path ordering issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With