Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run fastapi app from different path

Tags:

heroku

fastapi

my repo directory looks like

src/
notebooks/
web/
  one/
  two/
     app/

when I am under two I can lunch my fastapi app using

uvicorn app.app:app --reload --host=0.0.0.0 --port=7000

however, I am going to deploy my model on heorku and the Procfile should be at the main path. I know I have to make a Procfile and add

web: uvicorn app.app:app --reload --host=0.0.0.0 --port=7000

but I can't run the app from other folders. It would give the error

ModuleNotFoundError: No module named 'app'

UPDATE

the output of find web/two/app is as following enter image description here

so when I run uvicorn web.two.app.app:app --reload --port=7000

the error is enter image description here

like image 522
Areza Avatar asked Feb 19 '26 12:02

Areza


1 Answers

You have to provide the entire path from root to the app. In your case it should look like this:

uvicorn web.two.app.app:app --reload --host=0.0.0.0 --port=7000

like image 96
Mark Avatar answered Feb 27 '26 07:02

Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!