简体   繁体   中英

ModuleNotFoundError: No module named 'games.wsgi' when deploying Django app to heroku

I'm trying to deploy a Django app to heroku. I get an error of ModuleNotFoundError: No module named 'games.wsgi' where games is my project name. My Procfile created is web: gunicorn games.wsgi . I have installed gunicorn. My requirements.txt is

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

and pipfile also has [packages] gunicorn = "*" my wsgi file has os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'games.settings')

my heroku logs show

 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





My directory structure is

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


Can someone help I have been trying to figure out but everything seems to be correct but still I'm getting this error

Probably it's about Python path. Had the same problem on Centos8.

Simply changed PYTHONPATH to the directory wsgi.py is in.
In case of Linux it would be export PYTHONPATH='D/games/games'.
If you use IDE, you can manage PYTHONPATH from IDE settings.

Then step one level upper to 'D/games' and then try gunicorn games.wsgi:application .

idk how to change pythonath on Windows but seems this article is all about it: How to add to the PYTHONPATH in Windows, so it finds my modules/packages?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM