I have a folder that has my venv with dependencies and a python file.
When I run the python file with python main.py it works.
When I run the python file with uvicorn main:app --reload it throws a module not found error for all my dependencies. I want to turn the main.py into a fastapi app and installed fastapi and uvicorn to my venv and did app = FASTAPI()
Why is it working when running python but uvicorn is not finding my dependencies?
I uninstalled uvicorn and reinstalled it in my venv. I was expecting it to find my dependencies in my venv folder
I find the easiest solution for this to be to run uvicorn as a python module
python -m uvicorn main:app --reload
assuming the root of your problems is that your uvicorn main:app --reload is not respecting your venv
Probably you installed uvicorn outside of your virtual environment too, so when you run the command in terminal it tries to use that installation instead of the venv's version and doesn't find the dependencies.
Try calling uvicorn with the entire path, like this:
./venv/bin/uvicorn main:app --reload
Replace ./venv/ with the folder of your virtual environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With