fastapi crash on deploy, univorn start command works locally
Hi team, using railway for the first time,
build command is empty,
build logs:
Using subdirectory "app"
...
[succeeds]
start command: uvicorn app.server.api:app --host=0.0.0.0
(my dir structure is: /app/server/api.py, which has app = FastAPI()
app crashes on error:
ModuleNotFoundError: No module named 'app'
44 Replies
Project ID:
114fa538-776d-4163-b35a-d202c7fa380d
114fa538-776d-4163-b35a-d202c7fa380d
when you run your start command locally, what folder are you in?
root
wondering if it's because build uses app/ subdir, that the command should be relative to /app/?
you got it, try launching server.api:app instead
so railway infers the project dir for build?
thanks will try now
Railway copies your project files into a folder called /app/
so if you have a /app folder that is not your root, the structure should be /app/app/server/app etc
but it sounds to me like your /app is set to your root folder
still get:
in settings I left "root dir" field empty
let me try uvicorn app.app.server.api:app next?
can you share your repo structure?
sure try that out
api.py has
hmm app/server/api should work… Let me know if app/app/.. works
looks like they have their entire project located within a sub folder, maybe you could try setting the root directory to
/app
in the service settings, and then go back to the start command that works locallyI think I started with this, but will try again
actually, looks to me like app/server/ should be your root dir. your requirements.txt is in there
And then change the start command to server/api:
yeah either way this is a unorthodox project structure
actually I think req.txt is in app/
yep you’re right, the tab spacing is hard to read
app it is then
would it be easier if I just unnest the /app layer?
yeah, railway will be able to read it for itself then and you won’t have to specify a start command
your manage.py being within server is strange, it should be at the root of your project (or wherever req.txt is)
oh this manager.py is business logic related, not a server config
lookslike setting /app as root and modifying command also crashed, so I'll try unnesting project structure
oh it's fastapi haha
yeah brody realized that and deleted lol
love django too 😁
I’m a flask user, personally
django apis are too complicated
so what should I try next?
did unnesting the project structure work?
does the error trace back to a specific line?
as for errors, I noticed it's using python 3.8
(I'm using 3.12)
I don’t think 12 is supported atm
sorry adam
hey
rude
ahh yeah that’ll be better
still don’t know if 12 is supported though
its not 😦
but 3.11 should be sufficient
can try 3.11, didn't use any 3.12 exclusives
is it just this?
where runtime.txt is at project root
that should work, but it really only needs to be
3.11
gotcha, trying now
pretty sure it should be python-3.11, but we’ll see
not sure about not having python there
I think the matcher is just regex looking for some numbers, so either works
btw this was resolved, thanks!
I forgot how to mark it as so, please let me know if that's a feature
actuallly quick followup, deploy logs say:
INFO: Started server process [7]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
however visiting the site: https://agency-brain-production.up.railway.app/
just gives:
in dev, http://localhost:8000/ gives "hello world"please see the uvicorn section https://docs.railway.app/guides/fixing-common-errors#solution
works like a charm, thanks a bunch guys!
no problem