'The 'uvloop>=0.14.0' distribution was not found and is required by uvicorn

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.



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

pip uninstall -r requirements.txt -y

and then install FastAPI using

pip install FastAPI[all]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ayushma
Solution 2 Antoine
Solution 3 Dharman