No Module named 'fastapi' – Ubuntu environment

Question:

Though I have pip and pip3 installed fastapi library in my Ubuntu based workstation, I get a weird error saying

No module named ‘fastapi’.

I have been scratching my head since two days ago as the same code works in other laptop with same Ubuntu environment.

enter image description here

Uninstalled and reinstalled fastapi library

Asked By: Bharat R

||

Answers:

  1. Maybe you are using the wrong env? It looks like you’re using vscode so you can specify the interpeter
  2. Try pip install --upgrade pip and then pip install fastapi again
  3. Try using conda, and do conda install -c conda-forge fastapi
Answered By: arrmansa

you’re not using the correct environment to run your code.
Either, 1. install the package fast-api in the environment you running the code in or 2. switch to the other one the packages are installed in:

for 1:
sudo /bin/python3 -m pip install "fastapi[all]"

in this case you should be able to use the fast-api package
Note: the other packages you use are probably not installed as well

Answered By: bsatprivat
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.