linux 尝试在CentOS 7上运行FastAPI应用程序,但出现模块“asyncio”错误

wsxa1bj1  于 2023-03-07  发布在  Linux
关注(0)|答案(1)|浏览(247)

我尝试在CentOS 7上运行一个简单的FastAPI应用程序,但出现了一些错误。我将包含一些上下文的详细信息:
Python版本- 3.6.8 pip版本- 9.0.3
我使用以下命令运行应用程序:python3 -m uvicorn main:app
我一直收到这个错误:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/site-packages/uvicorn/__main__.py", line 4, in <module>
    uvicorn.main()
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/uvicorn/main.py", line 435, in main
    run(app, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/uvicorn/main.py", line 461, in run
    server.run()
  File "/usr/local/lib/python3.6/site-packages/uvicorn/server.py", line 67, in run
    return asyncio.run(self.serve(sockets=sockets))
AttributeError: module 'asyncio' has no attribute 'run'

我最初得到这个错误-/home/centos/fast_api/fastapi-tutorial/python3-venv/bin/python3: No module named uvicorn,但通过pip3 install uvicorn安装uvicorn后,我现在得到“模块'asyncio'错误”
任何帮助都很好
我已经尝试在服务器上启用python虚拟环境,但仍然得到相同的错误。
这是Python版本的问题吗?

whlutmcx

whlutmcx1#

FastAPI requires Python 3.7+,它与您的解释器不兼容。
在本例中,应用程序失败是因为Python 3.7中添加了asyncio.run()函数。

相关问题