首页 > 解决方案 > 如何使用 pip3 安装 websocket?

问题描述

我收到以下错误。有人知道如何正确安装吗?谢谢。

$ pip3 install websocket
Collecting websocket
  Using cached websocket-0.2.1.tar.gz (195 kB)
Collecting gevent
  Using cached gevent-20.5.2.tar.gz (5.6 MB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /private/tmp/mktemp/pip-build-env-u69lfxee/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools >= 40.8.0' wheel 'Cython >= 3.0a5' 'cffi >= 1.12.3 ; platform_python_implementation == '"'"'CPython'"'"'' 'greenlet>=0.4.14 ; platform_python_implementation == '"'"'CPython'"'"''
       cwd: None
  Complete output (14 lines):
  Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
      "__main__", mod_spec)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/__main__.py", line 23, in <module>
      from pip._internal.cli.main import main as _main  # isort:skip # noqa
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 5, in <module>
      import locale
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/locale.py", line 16, in <module>
      import re
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 143, in <module>
      class RegexFlag(enum.IntFlag):
  AttributeError: module 'enum' has no attribute 'IntFlag'
  ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /private/tmp/mktemp/pip-build-env-u69lfxee/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools >= 40.8.0' wheel 'Cython >= 3.0a5' 'cffi >= 1.12.3 ; platform_python_implementation == '"'"'CPython'"'"'' 'greenlet>=0.4.14 ; platform_python_implementation == '"'"'CPython'"'"'' Check the logs for full command output.

标签: pythonwebsocketpip

解决方案


这是因为您的 enum 不是标准库 enum 模块。您可能已经安装了包 enum34。

检查是否是这种情况的一种方法是检查属性枚举。文件

import enum
print(enum.__file__)  
# standard library location should be something like 
# /usr/local/lib/python3.6/enum.py

从 python 3.6 开始, enum34 库不再与标准库兼容。该库也不是必需的,因此您只需将其卸载即可。

pip uninstall -y enum34 如果您需要代码在 <=3.4 和 >3.4 的 python 版本上运行,您可以尝试将 enum-compat 作为要求。它只为没有标准库枚举的旧版本的 python 安装 enum34。


推荐阅读