Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found when running uvicorn

I have created a FastAPI app that is using the python library here

https://github.com/swar/nba_api

When I run the command

uvicorn main:app --reload

I get that the module nba_api is not found. I have installed this module using pip and am currently using a Python virtualenv (can see the nba_api in the lib/python3.10/site-packages file). When I just run the main.py file using

python3 main.py

the module is found. Any ideas why this would be the case?

Ran

uvicorn main:app --reload

was expecting my web server to load and to be able to hit the API endpoints that would use this python library, however uvicorn server failed to load.

Can call library if I invoke using

python3 main.py
like image 969
Austin Prince Avatar asked Nov 01 '25 08:11

Austin Prince


2 Answers

My crystal ball says you've installed uvicorn outside the virtualenv; if that's the case, uninstall it from the ambient environment, then install it only in the virtualenv, and try again.

like image 112
AKX Avatar answered Nov 02 '25 22:11

AKX


.venv is sometimes behaving in a strange way. So, I think, if uvicorn was already installed previously, even if you installed it in the virtual environment, it picks up from the base/root environment.

So, uninstalling uvicorn package from base/root environment, and then installing it again in virtual environment should solve the issue.

like image 24
Aurora Makovac Avatar answered Nov 02 '25 23:11

Aurora Makovac