ModuleNotFoundError:将 Django 应用程序部署到 heroku 时没有名为 'games.wsgi' 的模块



我正在尝试将Django应用程序部署到heroku。我得到一个ModuleNotFoundError: No module named 'games.wsgi'的错误,其中games是我的项目名称。我创建的Procfile是CCD_ 2。我安装了gunicorn。我的requirements.txt是

asgiref==3.3.4
Django==3.2
gunicorn==20.1.0
pytz==2021.1
sqlparse==0.4.1

pipfile也有[packages] gunicorn = "*"我的wsgi文件有os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'games.settings')

我的heroku日志显示

File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 551, in manage_workers
2021-06-14T10:51:35.947270+00:00 app[web.1]: self.spawn_workers()
2021-06-14T10:51:35.947294+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 623, in spawn_workers
2021-06-14T10:51:35.947812+00:00 app[web.1]: time.sleep(0.1 * random.random())
2021-06-14T10:51:35.947840+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2021-06-14T10:51:35.948243+00:00 app[web.1]: self.reap_workers()
2021-06-14T10:51:35.948270+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2021-06-14T10:51:35.948797+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2021-06-14T10:51:35.949024+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2021-06-14T10:51:35.949049+00:00 app[web.1]:
2021-06-14T10:51:35.949050+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2021-06-14T10:51:35.949050+00:00 app[web.1]:
2021-06-14T10:51:35.949077+00:00 app[web.1]: Traceback (most recent call last):
2021-06-14T10:51:35.949147+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2021-06-14T10:51:35.949409+00:00 app[web.1]: sys.exit(run())
2021-06-14T10:51:35.949438+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
2021-06-14T10:51:35.949744+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2021-06-14T10:51:35.949767+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 231, in run
2021-06-14T10:51:35.950117+00:00 app[web.1]: super().run()
2021-06-14T10:51:35.950143+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 72, in run
2021-06-14T10:51:35.950381+00:00 app[web.1]: Arbiter(self).run()
2021-06-14T10:51:35.950404+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 229, in run
2021-06-14T10:51:35.950785+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2021-06-14T10:51:35.950813+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 342, in halt
2021-06-14T10:51:35.951272+00:00 app[web.1]: self.stop()
2021-06-14T10:51:35.951300+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 393, in stop
2021-06-14T10:51:35.951781+00:00 app[web.1]: time.sleep(0.1)
2021-06-14T10:51:35.951810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2021-06-14T10:51:35.952157+00:00 app[web.1]: self.reap_workers()
2021-06-14T10:51:35.952180+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2021-06-14T10:51:35.952629+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2021-06-14T10:51:35.952784+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2021-06-14T10:51:36.054399+00:00 heroku[web.1]: Process exited with status 1
2021-06-14T10:51:36.153878+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-14T10:55:27.000000+00:00 app[api]: Build started by user myname.com
2021-06-14T10:55:50.869971+00:00 app[api]: Deploy dbdd2c5e by user myname.com
2021-06-14T10:55:50.869971+00:00 app[api]: Release v17 created by user myname@gmail.com
2021-06-14T10:55:51.193981+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-14T10:55:56.765467+00:00 heroku[web.1]: Starting process with command `gunicorn games.wsgi`
2021-06-14T10:55:59.711217+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-06-14T10:55:59.711739+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [4] [INFO] Listening at: http://0.0.0.0:14430 (4)
2021-06-14T10:55:59.711817+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [4] [INFO] Using worker: sync
2021-06-14T10:55:59.715825+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [8] [INFO] Booting worker with pid: 8
2021-06-14T10:55:59.722359+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [8] [ERROR] Exception in worker process
2021-06-14T10:55:59.722360+00:00 app[web.1]: Traceback (most recent call last):
2021-06-14T10:55:59.722361+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-14T10:55:59.722361+00:00 app[web.1]: worker.init_process()
2021-06-14T10:55:59.722361+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-14T10:55:59.722362+00:00 app[web.1]: self.load_wsgi()
2021-06-14T10:55:59.722362+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-14T10:55:59.722362+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-14T10:55:59.722363+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-14T10:55:59.722363+00:00 app[web.1]: self.callable = self.load()
2021-06-14T10:55:59.722363+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-14T10:55:59.722363+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-14T10:55:59.722363+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-14T10:55:59.722364+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-14T10:55:59.722364+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-14T10:55:59.722364+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-14T10:55:59.722364+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-14T10:55:59.722365+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-14T10:55:59.722365+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-14T10:55:59.722365+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-14T10:55:59.722365+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
2021-06-14T10:55:59.722366+00:00 app[web.1]: ModuleNotFoundError: No module named 'games.wsgi'
2021-06-14T10:55:59.722473+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-06-14T10:55:59.738771+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [9] [INFO] Booting worker with pid: 9
2021-06-14T10:55:59.746563+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [9] [ERROR] Exception in worker process
2021-06-14T10:55:59.746564+00:00 app[web.1]: Traceback (most recent call last):
2021-06-14T10:55:59.746565+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2021-06-14T10:55:59.746565+00:00 app[web.1]: worker.init_process()
2021-06-14T10:55:59.746565+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2021-06-14T10:55:59.746566+00:00 app[web.1]: self.load_wsgi()
2021-06-14T10:55:59.746566+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2021-06-14T10:55:59.746566+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2021-06-14T10:55:59.746567+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2021-06-14T10:55:59.746567+00:00 app[web.1]: self.callable = self.load()
2021-06-14T10:55:59.746567+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2021-06-14T10:55:59.746568+00:00 app[web.1]: return self.load_wsgiapp()
2021-06-14T10:55:59.746568+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2021-06-14T10:55:59.746568+00:00 app[web.1]: return util.import_app(self.app_uri)
2021-06-14T10:55:59.746568+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2021-06-14T10:55:59.746568+00:00 app[web.1]: mod = importlib.import_module(module)
2021-06-14T10:55:59.746569+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2021-06-14T10:55:59.746569+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2021-06-14T10:55:59.746569+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-06-14T10:55:59.746569+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-06-14T10:55:59.746570+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
2021-06-14T10:55:59.746570+00:00 app[web.1]: ModuleNotFoundError: No module named 'games.wsgi'
2021-06-14T10:55:59.746797+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [9] [INFO] Worker exiting (pid: 9)
2021-06-14T10:55:59.769510+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2021-06-14T10:55:59.868197+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [4] [INFO] Shutting down: Master
2021-06-14T10:55:59.868318+00:00 app[web.1]: [2021-06-14 10:55:59 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-06-14T10:55:59.935108+00:00 heroku[web.1]: Process exited with status 3
2021-06-14T10:56:00.034150+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-14T10:56:01.000000+00:00 app[api]: Build succeeded
2021-06-14T10:56:14.181661+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gameportaladitya.herokuapp.com request_id=3c6f34d2-b6cd-4d58-a6b2-985e495daf0f fwd="122.177.148.42" dyno= connect= service= status=503 bytes= protocol=https
2021-06-14T10:56:15.394506+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gameportaladitya.herokuapp.com request_id=5693205c-1af0-4846-be22-cf96d5306131 fwd="122.177.148.42" dyno= connect= service= status=503 bytes= protocol=https
2021-06-14T10:56:34.499111+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gameportaladitya.herokuapp.com request_id=b3f8aa4e-b89f-4112-8330-fe52851ff034 fwd="122.177.148.42" dyno= connect= service= status=503 bytes= protocol=https
2021-06-14T10:56:36.300878+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gameportaladitya.herokuapp.com request_id=5b31ffe7-48a2-4751-a388-a526447b1179 fwd="122.177.148.42" dyno= connect= service= status=503 bytes= protocol=https


我的目录结构是

D:.
│   .gitignore
│   Pipfile
│   Pipfile.lock
│   Procfile
│   requirements.txt
│   
│   
└───games
│   db.sqlite3
│   manage.py
│   
├───games
│       asgi.py
│       settings.py
│       urls.py
│       wsgi.py
│       __init__.py
│       
├───my_games
│   │   admin.py
│   │   apps.py
│   │   models.py
│   │   tests.py
│   │   views.py
│   │   __init__.py
│   │   
│   └───migrations
│           0001_initial.py
│           __init__.py
│           
├───static

有人能帮我吗我一直在想办法,但一切似乎都是正确的,但我仍然收到这个错误

可能是关于Python路径的。在Centos8上也遇到了同样的问题。

只需将PYTHONPATH更改为wsgi.py所在的目录。
在Linux的情况下,它将被导出PYTHON帕斯="D/games/games">
如果使用IDE,则可以通过IDE设置管理PYTHONPATH。

然后向上一级进入"D/games",然后尝试gunicorn games.wsgi:application

idk如何在Windows上更改pythonath,但这篇文章似乎都是关于它的:如何在Windows中添加到PYTHONPATH,以便它找到我的模块/包?

相关内容

  • 没有找到相关文章

最新更新