WSGI 无法加载为 Python 模块

WSGI cannot be loaded as Python module

我遇到了这个错误

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

加载了许多 Python / Django 项目之前,我从未使用过它
mkdir directory
cd directory
virtualenv env 
env/bin/pip install -r requirements.txt 

然后 FTP 在文件中然后

env/bin/python manage.py migrate
env/bin/python manage.py collectstatic
env/bin/python manage.py createsuperuser

今天没用。我读过许多有类似问题的帖子,但它们似乎是由于 python 的不同版本造成的。我的不是。任何想法。

添加了编辑追溯

 mod_wsgi (pid=8982): Target WSGI script '/var/www/mattscott/mainapp/wsgi.py' cannot be loaded as Python module.
 mod_wsgi (pid=8982): Exception occurred processing WSGI script '/var/www/mattscott/mainapp/wsgi.py'.
 Traceback (most recent call last):
   File "/var/www/mattscott/mainapp/wsgi.py", line 16, in <module>
     application = get_wsgi_application()
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
     django.setup(set_prefix=False)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/__init__.py", line 22, in setup
     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
     self._setup(name)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
     self._wrapped = Settings(settings_module)
   File "/var/www/mattscott/env/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
     mod = importlib.import_module(self.SETTINGS_MODULE)
   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
     __import__(name)
   ImportError: No module named mainapp.settings

找到了解决方案,但我认为这是其他问题的征兆(我希望 Graham 会解释)。

我添加了:

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

wsgi.py