I'm trying to deploy my app and gunicorn works locally but on heroku it doesn't work and it returns a module not found error.
Locally, I have noticed that when I run gunicorn locally it works when I'm on the same file as manage.py but when I cd into the higher level file that has the procfile and requirements.txt, it states that "No module named 'SC_BASIS.wsgi'" and the app crashes.
My current file directory looks like this:
or in words:
- SCBASIS_Website
- Procfile
- SC_BASIS
- SCBASIS
- SC_BASIS
- db.sqlite3
- files
- manage.py
- README.md
- requirements.txt
My procfile has the following process:
web gunicorn SC_BASIS.wsgi
When I run gunicorn locally it works in the file where manage.py is.
(base) antheaguo@Anthea SCBASIS_Website % cd SC_BASIS
(base) antheaguo@Anthea SC_BASIS % gunicorn SC_BASIS.wsgi
[2024-01-23 14:18:41 -0800] [38700] [INFO] Starting gunicorn 20.1.0
[2024-01-23 14:18:41 -0800] [38700] [INFO] Listening at: http://127.0.0.1:8000 (38700)
[2024-01-23 14:18:41 -0800] [38700] [INFO] Using worker: sync
[2024-01-23 14:18:41 -0800] [38701] [INFO] Booting worker with pid: 38701
however when I gocd.. to go up a file and run gunicorn SCBASIS.wsgi, it gives me the error message:
(base) antheaguo@Anthea SC_BASIS % cd ..
(base) antheaguo@Anthea SCBASIS_Website % gunicorn SC_BASIS.wsgi
[2024-01-23 14:20:13 -0800] [38723] [INFO] Starting gunicorn 20.1.0
[2024-01-23 14:20:13 -0800] [38723] [INFO] Listening at: http://127.0.0.1:8000 (38723)
[2024-01-23 14:20:13 -0800] [38723] [INFO] Using worker: sync
[2024-01-23 14:20:13 -0800] [38724] [INFO] Booting worker with pid: 38724
[2024-01-23 14:20:13 -0800] [38724] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/Users/antheaguo/anaconda3/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/Users/antheaguo/anaconda3/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/Users/antheaguo/anaconda3/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/Users/antheaguo/anaconda3/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/Users/antheaguo/anaconda3/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/Users/antheaguo/anaconda3/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/Users/antheaguo/anaconda3/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/Users/antheaguo/anaconda3/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'SC_BASIS.wsgi'
[2024-01-23 14:20:13 -0800] [38724] [INFO] Worker exiting (pid: 38724)
[2024-01-23 14:20:13 -0800] [38723] [INFO] Shutting down: Master
[2024-01-23 14:20:13 -0800] [38723] [INFO] Reason: Worker failed to boot.
(base) antheaguo@Anthea SCBASIS_Website %
When I look at the logs on heroku using the command heroku logs --tail to see why my app can't deploy it gives me similar error messages:
2024-01-23T22:08:29.280751+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2024-01-23T22:08:29.280751+00:00 app[web.1]: ^^^^^^^^^^^^^^^
2024-01-23T22:08:29.280752+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/base.py", line 67, in wsgi
2024-01-23T22:08:29.280752+00:00 app[web.1]: self.callable = self.load()
2024-01-23T22:08:29.280752+00:00 app[web.1]: ^^^^^^^^^^^
2024-01-23T22:08:29.280752+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2024-01-23T22:08:29.280752+00:00 app[web.1]: return self.load_wsgiapp()
2024-01-23T22:08:29.280753+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.280753+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2024-01-23T22:08:29.280753+00:00 app[web.1]: return util.import_app(self.app_uri)
2024-01-23T22:08:29.280753+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.280753+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/util.py", line 371, in import_app
2024-01-23T22:08:29.280753+00:00 app[web.1]: mod = importlib.import_module(module)
2024-01-23T22:08:29.280754+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.280754+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/importlib/__init__.py", line 90, in import_module
2024-01-23T22:08:29.280755+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2024-01-23T22:08:29.280755+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.280755+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2024-01-23T22:08:29.280755+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2024-01-23T22:08:29.280755+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
2024-01-23T22:08:29.280756+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
2024-01-23T22:08:29.280756+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2024-01-23T22:08:29.280756+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2024-01-23T22:08:29.280756+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
2024-01-23T22:08:29.280756+00:00 app[web.1]: ModuleNotFoundError: No module named 'SC_BASIS/SC_BASIS'
2024-01-23T22:08:29.280807+00:00 app[web.1]: [2024-01-23 22:08:29 +0000] [7] [INFO] Worker exiting (pid: 7)
2024-01-23T22:08:29.297492+00:00 app[web.1]: [2024-01-23 22:08:29 +0000] [8] [INFO] Booting worker with pid: 8
2024-01-23T22:08:29.299618+00:00 app[web.1]: [2024-01-23 22:08:29 +0000] [2] [ERROR] Worker (pid:7) exited with code 3
2024-01-23T22:08:29.301123+00:00 app[web.1]: [2024-01-23 22:08:29 +0000] [8] [ERROR] Exception in worker process
2024-01-23T22:08:29.301124+00:00 app[web.1]: Traceback (most recent call last):
2024-01-23T22:08:29.301124+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
2024-01-23T22:08:29.301125+00:00 app[web.1]: worker.init_process()
2024-01-23T22:08:29.301125+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/workers/base.py", line 134, in init_process
2024-01-23T22:08:29.301125+00:00 app[web.1]: self.load_wsgi()
2024-01-23T22:08:29.301125+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2024-01-23T22:08:29.301126+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2024-01-23T22:08:29.301126+00:00 app[web.1]: ^^^^^^^^^^^^^^^
2024-01-23T22:08:29.301126+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/base.py", line 67, in wsgi
2024-01-23T22:08:29.301126+00:00 app[web.1]: self.callable = self.load()
2024-01-23T22:08:29.301126+00:00 app[web.1]: ^^^^^^^^^^^
2024-01-23T22:08:29.301127+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2024-01-23T22:08:29.301127+00:00 app[web.1]: return self.load_wsgiapp()
2024-01-23T22:08:29.301127+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.301127+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2024-01-23T22:08:29.301127+00:00 app[web.1]: return util.import_app(self.app_uri)
2024-01-23T22:08:29.301129+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.301129+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/util.py", line 371, in import_app
2024-01-23T22:08:29.301129+00:00 app[web.1]: mod = importlib.import_module(module)
2024-01-23T22:08:29.301130+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.301130+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/importlib/__init__.py", line 90, in import_module
2024-01-23T22:08:29.301130+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2024-01-23T22:08:29.301130+00:00 app[web.1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-01-23T22:08:29.301131+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2024-01-23T22:08:29.301131+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2024-01-23T22:08:29.301131+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
2024-01-23T22:08:29.301131+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
2024-01-23T22:08:29.301131+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
2024-01-23T22:08:29.301131+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
2024-01-23T22:08:29.301132+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
2024-01-23T22:08:29.301132+00:00 app[web.1]: ModuleNotFoundError: No module named 'SC_BASIS/SC_BASIS'
2024-01-23T22:08:29.301190+00:00 app[web.1]: [2024-01-23 22:08:29 +0000] [8] [INFO] Worker exiting (pid: 8)
2024-01-23T22:08:29.320969+00:00 app[web.1]: [2024-01-23 22:08:29 +0000] [2] [ERROR] Worker (pid:8) exited with code 3
2024-01-23T22:08:29.321021+00:00 app[web.1]: Traceback (most recent call last):
2024-01-23T22:08:29.321031+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 202, in run
2024-01-23T22:08:29.321244+00:00 app[web.1]: self.manage_workers()
2024-01-23T22:08:29.321285+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 571, in manage_workers
2024-01-23T22:08:29.321474+00:00 app[web.1]: self.spawn_workers()
2024-01-23T22:08:29.321508+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 643, in spawn_workers
2024-01-23T22:08:29.321684+00:00 app[web.1]: time.sleep(0.1 * random.random())
2024-01-23T22:08:29.321720+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2024-01-23T22:08:29.321827+00:00 app[web.1]: self.reap_workers()
2024-01-23T22:08:29.321848+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 530, in reap_workers
2024-01-23T22:08:29.321993+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2024-01-23T22:08:29.322069+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2024-01-23T22:08:29.322078+00:00 app[web.1]:
2024-01-23T22:08:29.322084+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2024-01-23T22:08:29.322093+00:00 app[web.1]:
2024-01-23T22:08:29.322104+00:00 app[web.1]: Traceback (most recent call last):
2024-01-23T22:08:29.322115+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2024-01-23T22:08:29.322230+00:00 app[web.1]: sys.exit(run())
2024-01-23T22:08:29.322341+00:00 app[web.1]: ^^^^^
2024-01-23T22:08:29.322353+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
2024-01-23T22:08:29.322607+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2024-01-23T22:08:29.322636+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/base.py", line 236, in run
2024-01-23T22:08:29.322794+00:00 app[web.1]: super().run()
2024-01-23T22:08:29.322820+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/app/base.py", line 72, in run
2024-01-23T22:08:29.322877+00:00 app[web.1]: Arbiter(self).run()
2024-01-23T22:08:29.322904+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 229, in run
2024-01-23T22:08:29.323014+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2024-01-23T22:08:29.323049+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 342, in halt
2024-01-23T22:08:29.323145+00:00 app[web.1]: self.stop()
2024-01-23T22:08:29.323195+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 396, in stop
2024-01-23T22:08:29.323252+00:00 app[web.1]: time.sleep(0.1)
2024-01-23T22:08:29.323272+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2024-01-23T22:08:29.323346+00:00 app[web.1]: self.reap_workers()
2024-01-23T22:08:29.323367+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/gunicorn/arbiter.py", line 530, in reap_workers
2024-01-23T22:08:29.323493+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2024-01-23T22:08:29.323533+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2024-01-23T22:08:29.397804+00:00 heroku[web.1]: Process exited with status 1
2024-01-23T22:08:29.427664+00:00 heroku[web.1]: State changed from starting to crashed