WSGI无法作为Python模块加载

时间:2017-05-14 19:46:25

标签: python django python-2.7 django-wsgi

我收到此错误

  

'path-to / wsgi.py'无法作为Python模块加载。

在通过

加载许多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。我的不是。任何想法。

添加了EDIT Traceback

 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

1 个答案:

答案 0 :(得分:0)

找到一个解决方案,但我认为这是其他错误的症状(我希望格雷厄姆会解释)。

我添加了:

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

wsgi.py