python 未找到“uvloop>=0.14.0”分布,这是uvicorn所需的分布

mrwjdhj3  于 2023-01-29  发布在  Python
关注(0)|答案(5)|浏览(402)

我刚开始学习FastAPI,但一开始就卡住了。我一直收到以下错误:

(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

这是我的python代码:

from fastapi import FastAPI

app = FastAPI()

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

我已经尝试使用pip install -U uvloop pip, pip install uvloop==0.14.0,但没有修复。

bkkx9g8r

bkkx9g8r1#

我尝试使用以下命令运行,效果很好:
python -m uvicorn主程序:应用程序--重新加载
这里main是你的文件名

ct3nt3jp

ct3nt3jp2#

pip uninstall -r requirements.txt -y

然后使用安装FastAPI

pip install FastAPI[all]
50few1ms

50few1ms3#

我遇到了这样的问题。首先,激活你的venv:

source venv/bin/activate

要求中的冷冻和安全管道列表:

pip freeze > requirements.txt

卸载:

pip uninstall -r requirements.txt -y

停用:

rm -r venv/

在此之后,你必须重新制作venv:

python3 -m venv venv

并安装所有必需的文件。

4sup72z8

4sup72z84#

我通过在根python上的virtualenv之外安装Python需求解决了这个问题
pip freeze > requirements.txt
deactivate
pip uninstall -r requirements.txt -y

0yg35tkg

0yg35tkg5#

pip安装uvicorn为我解决了这个问题

相关问题