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
Percy
Percy5mo ago
Project ID: 2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
Percy
Percy5mo ago
Project ID: 2ae4d6f5-aff1-40bc-926b-a21bfce1ede0
BlazingIce
BlazingIce5mo ago
2ae4d6f5-aff1-40bc-926b-a21bfce1ede0 Root directory was /api
Brody
Brody5mo ago
does this run locally?
BlazingIce
BlazingIce5mo ago
Yes
Brody
Brody5mo ago
what folder are you in when you run it locally, and what command do you run?
BlazingIce
BlazingIce5mo ago
flask run --port 8889 --debug in /api but i use railway up in /
Brody
Brody5mo ago
File "/app/app.py", line 8, in <module>
from api import app, db
ModuleNotFoundError: No module named 'api'
File "/app/app.py", line 8, in <module>
from api import app, db
ModuleNotFoundError: No module named 'api'
BlazingIce
BlazingIce5mo ago
I also tried from . import app, db defined app and db in __init__.py
Brody
Brody5mo ago
can you share your repo?
BlazingIce
BlazingIce5mo ago
GitHub
GitHub - Leo7Deng/SpotifySifter
Contribute to Leo7Deng/SpotifySifter development by creating an account on GitHub.
BlazingIce
BlazingIce5mo ago
Can provide env variables if u need
Brody
Brody5mo ago
your imports are wrong but your folder structure is also wrong
BlazingIce
BlazingIce5mo ago
How can I fix it
Brody
Brody5mo ago
your python imports im not sure, im not a python dev. but you should have your repo structured like this
.
├── api/
│ └── <python code here>
├── frontend/
│ └── <frontend code here>
├── .gitignore
└── README.MD
.
├── api/
│ └── <python code here>
├── frontend/
│ └── <frontend code here>
├── .gitignore
└── README.MD
i also see other issues with your frontend, but i doubt you wanna get into that too
BlazingIce
BlazingIce5mo ago
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
Brody
Brody5mo ago
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 repo
BlazingIce
BlazingIce5mo ago
Sorry 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
Brody
Brody5mo ago
instead of a __init__.py just have a more conventional config.py file or something that you import from
BlazingIce
BlazingIce5mo ago
Will try, thanks
Brody
Brody5mo ago
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
BlazingIce
BlazingIce5mo ago
Can you elaborate on how I'm running a development server
Brody
Brody5mo ago
react-scripts start starts a development server that should only ever be used locally, for development
BlazingIce
BlazingIce5mo ago
What should it be for not development
Brody
Brody5mo ago
i prefer using the caddy web server but fix the python thing and then we tackle the frontend
BlazingIce
BlazingIce5mo ago
True, let me do that thanks!
Brody
Brody5mo ago
so you got the api running on railway?
BlazingIce
BlazingIce5mo ago
yes, i also got the frontend to run on production i think i solved everything
Brody
Brody5mo ago
what makes you think the frontend is production ready now?
BlazingIce
BlazingIce5mo ago
i used serve -s build for the deploy command
Brody
Brody5mo ago
deploy command? you mean start command?
BlazingIce
BlazingIce5mo ago
yes start command
Brody
Brody5mo ago
thats not a bad way, but would you be interested in a solution that uses even less memory?
BlazingIce
BlazingIce5mo ago
yes what would be better?
Brody
Brody5mo ago
i mentioned it previously, caddy, i have a drop in solution for it, wanna do it?
BlazingIce
BlazingIce5mo ago
i think will first get my cron finished and come back to this, thanks for all the help
Brody
Brody5mo ago
sounds good!
Want results from more Discord servers?
Add your server
More Posts