6

I'm new at learning FastAPI, and I'm getting stuck at the very beginning. I keep getting the following error:

(venv) root@Xue:/home/proyectos/FastAPI# uvicorn main.py:app --reload
Traceback (most recent call last):
  File "/usr/bin/uvicorn", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3254, in <module>
    def _initialize_master_working_set():
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3237, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3266, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 584, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 901, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 787, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'uvloop>=0.14.0' distribution was not found and is required by uvicorn

this is my python code:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def home():
    return {'Hello': 'World'}

I already try with pip install -U uvloop pip, pip install uvloop==0.14.0 and no fix.

Xuerivera
  • 71
  • 1
  • 5
  • Check out that you may be using python 3.x, but installing libraries for python 2.x . Try using the command `pip3 install uvloop` – lsabi Nov 01 '21 at 09:20
  • 1
    Thanks, bro didn't work with pip3 install uvloop but I tried with pip3 install uvicorn, and worked fine – Xuerivera Nov 01 '21 at 23:37
  • @Xuerivera Good if you answer your own question and accept it as the solution. – hfm Jan 21 '22 at 22:14

5 Answers5

6

I tried running using the following command and this worked for me:

python -m uvicorn main:app --reload

here the main is your file name

Ayushma
  • 61
  • 1
  • 2
2
pip uninstall -r requirements.txt -y

and then install FastAPI using

pip install FastAPI[all]
Dharman
  • 30,962
  • 25
  • 85
  • 135
0

I had such a problem. First, activate your venv:

source venv/bin/activate

Freeze and safe pip list in requirements:

pip freeze > requirements.txt

Uninstall:

pip uninstall -r requirements.txt -y

Deactivate:

rm -r venv/

After this you have to remake venv:

python3 -m venv venv

And install all necessary files.

Antoine
  • 1,393
  • 4
  • 20
  • 26
0

I fixed this issue by installing my Python requirements outside of my virtualenv on my root python

pip freeze > requirements.txt

deactivate

pip uninstall -r requirements.txt -y

Jacob Solawetz
  • 358
  • 3
  • 5
0

pip install uvicorn solved the issue for me.

Max S.
  • 3,704
  • 2
  • 13
  • 34
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 31 '23 at 13:16