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