My django application loaded in Apache/mod_wsgi cannot find my exterior packages despite the fact that I specified it in sys.path?
The setup is the following:
a) the exterior packages have been in /var/www/site/my/python/config
b) the django website (using the configurations.py file) is within /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 configurations.py file begins using 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@example.com'), ) MANAGERS = ADMINS ....
The mistake I am 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 observe the configurations.py file is attempted loaded as "just before import" is printed, however the code failes on posting "my.python.config.ConfigParser". It appears to identify it as being python.config rather though?
I've been tearing my hair out all day long. Everything however works in eclipse atmosphere by directly invoking 'django-admin.py runserver 80' after setting the python path and also the django atmosphere variables. I additionally verified the python path is within sys.path.
I went from ideas, so ANY help could be much appreciated!
Add at oncoming of configurations.py:
import my print my.__file__
Validate the path printed out is perfect for the 'my' package you anticipate.
Quite simply, it may be obtaining another 'my' package due to this type of package existing in multiple locations and also the order of sys.path being wrong.
Also make certain you decide to go read:
which discusses sys.path ordering issues.
Have you got
__init__.py in most the subdirectories and it is kids of /var/www/site
whenever you access my.python.config,
__init__.py must be there within my directory, python directory and config directory.
Regarding permission, wsgi is going to be run as apache user (user you've specified by wsgi.conf). Take proper care of it.