我不知道如何在Ubuntu上修复这个错误。我正在尝试使用FastApi运行uvicorn
服务器
uvicorn.run("api:app", host="0.0.0.0", port=3100, reload=True, workers=10)
我试过pip3 install websockets
:
Collecting websockets
Downloading https://files.pythonhosted.org/packages/7e/86/cef054220bc080451fe9663ce7f99beda0599098241190b6b6dc1073ab92/websockets-10.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (112kB)
100% |████████████████████████████████| 112kB 5.9MB/s
Installing collected packages: websockets
Successfully installed websockets-8.1
我不知道还需要安装什么
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/server.py", line 67, in serve
config.load()
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/config.py", line 471, in load
ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/importer.py", line 24, in import_from_string
raise exc from None
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/protocols/websockets/auto.py", line 17, in <module>
from uvicorn.protocols.websockets.websockets_impl import WebSocketProtocol
File "/home/hafid/.local/lib/python3.7/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 9, in <module>
from websockets.datastructures import Headers
ModuleNotFoundError: No module named 'websockets.datastructures'
发布于 2022-10-16 19:00:33
需要更新setuptools和pip
pip3 install -U setuptools
pip3 install -U pip
发布于 2022-10-18 22:56:41
我也有同样的问题,我不知道为什么会这样,但我至少给你看看我的解决办法。
最好的办法是跑步:
pip uninstall websockets
pip install websockets
但是由于某些原因,这个命令无法为我卸载它,所以我手动完成了它。
因为u在Ubuntu中,所以以root用户的身份打开这个文件夹:
/usr/local/lib/python3.8/dist-packages/websocket
然后你可以在websockets当前版本文件手动下载这些文件。
在我的例子中,我注意到在我的旧websockets文件夹中,我没有websockets.datastructures
,也没有其他一些文件,比如文件夹、legacy
和extensions
,所以我只是将整个库解压缩到上面引用的路径上,这样就可以了。
发布于 2022-11-18 04:22:17
对我来说,这两个答案中的任何一个都是有效的。我只是用以下方式升级websockets:
pip install -U websockets
https://stackoverflow.com/questions/74089803
复制相似问题