工作进程中的异常:没有名为wsgi的模块

时间:2016-09-27 08:32:09

标签: python django heroku wsgi

我正在尝试在heroku上部署我的Django Web应用程序。 当我尝试打开它时,出现应用程序错误消息。

这是我的日志:

2016-09-27T07:56:16.836350+00:00 heroku[web.1]: State changed from crashed to starting
2016-09-27T07:56:21.160909+00:00 heroku[web.1]: Starting process with command `gunicorn myblog.wsgi --log-file -`
2016-09-27T07:56:24.063399+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [3] [INFO] Listening at: http://0.0.0.0:37485 (3)
2016-09-27T07:56:24.062805+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [3] [INFO] Starting gunicorn 19.4.5
2016-09-27T07:56:24.063556+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [3] [INFO] Using worker: sync
2016-09-27T07:56:24.066328+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [9] [INFO] Booting worker with pid: 9
2016-09-27T07:56:24.069171+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [9] [ERROR] Exception in worker process:
2016-09-27T07:56:24.069172+00:00 app[web.1]: Traceback (most recent call last):
2016-09-27T07:56:24.069175+00:00 app[web.1]:     worker.init_process()
2016-09-27T07:56:24.069175+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
2016-09-27T07:56:24.069176+00:00 app[web.1]:     self.load_wsgi()
2016-09-27T07:56:24.069174+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
2016-09-27T07:56:24.069177+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
2016-09-27T07:56:24.069178+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2016-09-27T07:56:24.069179+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2016-09-27T07:56:24.069179+00:00 app[web.1]:     self.callable = self.load()
2016-09-27T07:56:24.069180+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2016-09-27T07:56:24.069181+00:00 app[web.1]:     return self.load_wsgiapp()
2016-09-27T07:56:24.069181+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2016-09-27T07:56:24.069182+00:00 app[web.1]:     return util.import_app(self.app_uri)
2016-09-27T07:56:24.069183+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
2016-09-27T07:56:24.069183+00:00 app[web.1]:     __import__(module)
2016-09-27T07:56:24.069185+00:00 app[web.1]: Traceback (most recent call last):
2016-09-27T07:56:24.069185+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
2016-09-27T07:56:24.069186+00:00 app[web.1]:     worker.init_process()
2016-09-27T07:56:24.069184+00:00 app[web.1]: ImportError: No module named wsgi
2016-09-27T07:56:24.069186+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
2016-09-27T07:56:24.069187+00:00 app[web.1]:     self.load_wsgi()
2016-09-27T07:56:24.069188+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2016-09-27T07:56:24.069188+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
2016-09-27T07:56:24.069189+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2016-09-27T07:56:24.069189+00:00 app[web.1]:     self.callable = self.load()
2016-09-27T07:56:24.069190+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2016-09-27T07:56:24.069191+00:00 app[web.1]:     return self.load_wsgiapp()
2016-09-27T07:56:24.069191+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2016-09-27T07:56:24.069192+00:00 app[web.1]:     return util.import_app(self.app_uri)
2016-09-27T07:56:24.069193+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
2016-09-27T07:56:24.069193+00:00 app[web.1]:     __import__(module)
2016-09-27T07:56:24.069194+00:00 app[web.1]: ImportError: No module named wsgi
2016-09-27T07:56:24.069351+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [9] [INFO] Worker exiting (pid: 9)
2016-09-27T07:56:24.088872+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [3] [INFO] Shutting down: Master
2016-09-27T07:56:24.089020+00:00 app[web.1]: [2016-09-27 07:56:24 +0000] [3] [INFO] Reason: Worker failed to boot.
2016-09-27T07:56:24.210605+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-27T07:56:24.197593+00:00 heroku[web.1]: Process exited with status 3

我在日志中注意到的错误是:

  • [错误]工作进程中的异常:
  • ImportError:没有名为wsg的模块

我的procfile :(我的应用名为myblog)

web: gunicorn myblog.wsgi --log-file -

requirements.txt:

Django==1.9.2
argparse==1.2.1
dj-database-url==0.4.0
dj-static==0.0.6
django-toolbelt==0.0.1
gunicorn==19.4.5
psycopg2==2.6.1
static3==0.7.0
whitenoise==2.0.6
wsgiref==0.1.2

注意::我使用此命令禁用了Collectstatic

heroku config:set DISABLE_COLLECTSTATIC=1

EDIT :: -------------------------------------------- -------

我的wsgi.py文件:

import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

我的项目结构:

Django-Blog
   /blog
      settings.py
      urls.py
      wsgi.py
      __init__.py
   /myblog
   manage.py
   requirements.txt
   procfile
   runtime.txt
   /venv

.gitignore文件:

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject


myblog/static/myblog/images/
myblog/migrations/

.idea/workspace.xml

1 个答案:

答案 0 :(得分:2)

将您的proc文件更改为:

web: gunicorn blog.wsgi --log-file -