WSGI cannot be loaded as Python module

python django python-2.7 django-wsgi

1107 просмотра

1 ответ

I'm getting this error

'path-to/' cannot be loaded as Python module.

I've never had it before having loaded many Python / Django projects by

mkdir directory
cd directory
virtualenv env 
env/bin/pip install -r requirements.txt 

Then FTP in the files and then

env/bin/python migrate
env/bin/python collectstatic
env/bin/python createsuperuser

Today it isn't working. I've read a number of posts with similar issues but they seem to be due to different versions of python. Mine aren't. Any ideas.

EDIT Traceback added

 mod_wsgi (pid=8982): Target WSGI script '/var/www/mattscott/mainapp/' cannot be loaded as Python module.
 mod_wsgi (pid=8982): Exception occurred processing WSGI script '/var/www/mattscott/mainapp/'.
 Traceback (most recent call last):
   File "/var/www/mattscott/mainapp/", line 16, in <module>
     application = get_wsgi_application()
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/core/", line 13, in get_wsgi_application
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/", line 22, in setup
     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/", line 53, in __getattr__
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/", line 41, in _setup
     self._wrapped = Settings(settings_module)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/", line 97, in __init__
     mod = importlib.import_module(self.SETTINGS_MODULE)
   File "/usr/lib/python2.7/importlib/", line 37, in import_module
   ImportError: No module named mainapp.settings
Автор: HenryM Источник Размещён: 19.09.2019 03:53

Ответы (1)

0 плюса


Found a solution but I expect it is the symptom of something else wrong (I'm hoping Graham will explain).

I've added:

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:


Автор: HenryM Размещён: 15.05.2017 06:29
Вопросы из категории :