fastapi
fastapi copied to clipboard
[Question] Why ModuleNotFoundError: No module found
Example
from fastapi import FastAPI
import pandas.io.sql as sqlio
import psycopg2
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
uvicorn main:app --reload
Description
import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
Environment
-
OS: [e.g. Linux / Windows / macOS]:
-
Big Sur 11.4
-
FastAPI Version [e.g. 0.3.0]:
To know the FastAPI version use:
python -c "import fastapi; print(fastapi.__version__)"
0.66.0
- Python version:
To know the Python version use:
python --version
3.9.5
Additional context
pip3 list
Package Version
aiofiles 0.7.0 fastapi 0.66.0 numpy 1.21.0 pandas 1.2.5 pip 21.1.2 psycopg2 2.9.1 pydantic 1.8.2 rope 0.19.0 setuptools 52.0.0.post20210125 six 1.16.0 starlette 0.14.2 toml 0.10.2 tornado 6.1 traitlets 5.0.5 typing-extensions 3.10.0.0 uvicorn 0.14.0
You need to do pip install psycopg2-binary as well
Sorry I didnt make it clear, it is not just psycopg2 but pandas also not found as well
Have you use virtual environment? Maybe you can provide with stack traceback
@miriam-z This isn't a FastAPI issue, you need to make use of virtual environments or something like pipenv.
hey! i have the same problem. is it solved? if so can you explain it please?
I have the same problem too. How can I deal with it?
This is not a FastAPI issue but an import issue. It’s impossible to provide a general solution, as there can be many causes.