Gunicorn failed to deploy after building (new to railway)
Changed from api import app, db to many others like from . import app, db, not sure if this is the problem.
Procfile:
web: gunicorn app:app
[2024-01-18 06:18:33 +0000] [7] [INFO] Starting gunicorn 21.2.0
[2024-01-18 06:18:33 +0000] [7] [INFO] Listening at: http://0.0.0.0:7634 (7)
[2024-01-18 06:18:33 +0000] [7] [INFO] Using worker: sync
[2024-01-18 06:18:33 +0000] [11] [INFO] Booting worker with pid: 11
[2024-01-18 06:18:33 +0000] [11] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
worker.init_process()
File "/opt/venv/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/opt/venv/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/opt/venv/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/opt/venv/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/opt/venv/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
.
.
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/app.py", line 8, in <module>
from api import app, db
ModuleNotFoundError: No module named 'api'
37 Replies
Project ID:
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
Project ID:
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
Root directory was /api
does this run locally?
Yes
what folder are you in when you run it locally, and what command do you run?
flask run --port 8889 --debug in /api
but i use railway up in /
I also tried from . import app, db
defined app and db in __init__.py
can you share your repo?
GitHub
GitHub - Leo7Deng/SpotifySifter
Contribute to Leo7Deng/SpotifySifter development by creating an account on GitHub.
Can provide env variables if u need
your imports are wrong
but your folder structure is also wrong
How can I fix it
your python imports im not sure, im not a python dev.
but you should have your repo structured like this
i also see other issues with your frontend, but i doubt you wanna get into that too
Yeah haha first time doing web dev😅 , will restructure like you said, any idea how I can fix the issue for now? My frontend code deployed but not backend
im sorry i dont know, im not a python dev, my best advice would be to just try stuff, where does
api
come from in your import, i dont see it anywhere in the repoSorry just saw now, I think I gave wrong error message,
from . import app, db
ImportError: attempted relative import with no known parent package
I originally did something like this, any idea how to fix that, I know this is prob a python issue, it works locally like this and can't really find anything online to fix it
instead of a
__init__.py
just have a more conventional config.py file or something that you import fromWill try, thanks
when you solve this, please do come back so we can fix the issue with the frontend, you are running a development server, that will use a lot of resources, thus cost you a lot
Can you elaborate on how I'm running a development server
react-scripts start
starts a development server that should only ever be used locally, for developmentWhat should it be for not development
i prefer using the caddy web server
but fix the python thing and then we tackle the frontend
True, let me do that thanks!
so you got the api running on railway?
yes, i also got the frontend to run on production
i think i solved everything
what makes you think the frontend is production ready now?
i used serve -s build for the deploy command
deploy command?
you mean start command?
yes start command
thats not a bad way, but would you be interested in a solution that uses even less memory?
yes what would be better?
i mentioned it previously, caddy, i have a drop in solution for it, wanna do it?
i think will first get my cron finished and come back to this, thanks for all the help
sounds good!