在 Heroku 上部署 Django 应用程序时无法解决 ModuleNotFoundError

时间:2021-03-16 19:21:00

标签: django heroku deployment modulenotfounderror

当我尝试在 Heroku 上部署我的应用程序时,我的日志中不断出现以下错误:

    2021-03-16T19:03:43.053580+00:00 heroku[web.1]: Starting process with command `gunicorn todo.wsgi:application`
2021-03-16T19:03:46.709810+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [4] [INFO] Starting gunicorn 20.0.4
2021-03-16T19:03:46.711200+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [4] [INFO] Listening at: http://0.0.0.0:14087 (4)
2021-03-16T19:03:46.714536+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [4] [INFO] Using worker: sync
2021-03-16T19:03:46.720381+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [9] [INFO] Booting worker with pid: 9
2021-03-16T19:03:46.726148+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [9] [ERROR] Exception in worker process
2021-03-16T19:03:46.726159+00:00 app[web.1]: Traceback (most recent call last):
2021-03-16T19:03:46.726161+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2021-03-16T19:03:46.726163+00:00 app[web.1]: worker.init_process()
2021-03-16T19:03:46.726164+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in 
init_process
2021-03-16T19:03:46.726164+00:00 app[web.1]: self.load_wsgi()
2021-03-16T19:03:46.726164+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in 
load_wsgi
2021-03-16T19:03:46.726165+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-03-16T19:03:46.726166+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi 
2021-03-16T19:03:46.726167+00:00 app[web.1]: self.callable = self.load()
2021-03-16T19:03:46.726167+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2021-03-16T19:03:46.726167+00:00 app[web.1]: return self.load_wsgiapp()
2021-03-16T19:03:46.726168+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2021-03-16T19:03:46.726168+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-03-16T19:03:46.726169+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2021-03-16T19:03:46.726169+00:00 app[web.1]: mod = importlib.import_module(module)
2021-03-16T19:03:46.726170+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2021-03-16T19:03:46.726170+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-03-16T19:03:46.726170+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2021-03-16T19:03:46.726171+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2021-03-16T19:03:46.726171+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
2021-03-16T19:03:46.726178+00:00 app[web.1]: ModuleNotFoundError: No module named 'todo.wsgi'
2021-03-16T19:03:46.726318+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-03-16T19:03:46.757758+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [4] [INFO] Shutting down: Master
2021-03-16T19:03:46.757919+00:00 app[web.1]: [2021-03-16 19:03:46 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-03-16T19:03:46.862677+00:00 heroku[web.1]: Process exited with status 3
2021-03-16T19:03:46.968721+00:00 heroku[web.1]: State changed from starting to crashed
2021-03-16T19:04:06.117589+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=awesomedjangotodolistapp.herokuapp.com request_id=a901a457-1b6b-4520-85d4-7c8282840444 fwd="49.207.195.121" dyno= connect= service= status=503 bytes= protocol=https   
2021-03-16T19:04:06.459303+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=awesomedjangotodolistapp.herokuapp.com request_id=34922463-fb00-4fc3-a8ec-37c802dcfd1f fwd="49.207.195.121" dyno= connect= service= status=503 bytes= protocol=https
2021-03-16T19:04:10.265232+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=awesomedjangotodolistapp.herokuapp.com request_id=44c8e399-efc6-4693-b571-07bf37c773da fwd="49.207.195.121" dyno= connect= service= status=503 bytes= protocol=https   
2021-03-16T19:04:10.606797+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=awesomedjangotodolistapp.herokuapp.com request_id=54b508bf-12f7-4cdc-bc7e-86f797c60b91 fwd="49.207.195.121" dyno= connect= service= status=503 bytes= protocol=https

显然该错误与 ModuleNotFoundError: No module named 'todo.wsgi' 行有关,因为我的 Procfile 确实 存在于 todo 目录中,所以我无法理解这一行。 这是我的目录树:

todo_list is the app directory

tod​​o_list 是应用程序目录。我的 Procfile 看起来像这样:

web: gunicorn todo.wsgi:application

我该如何解决这个问题? todo.wsgi 不是模块/目录,但 todo 是,不是吗?我的 Procfile 版本适用于其他人,但不适用于我。

1 个答案:

答案 0 :(得分:0)

将您的 Procfile 编辑为以下内容:

web: gunicorn todo.wsgi