为什么 'pip3 install netifaces' 在 Debian 10 Buster 上失败?

Why is 'pip3 install netifaces' failing on Debian 10 Buster?

我在 AWS EC2 上设置了一个新的 Debian 10 (Buster) 实例,并且能够安装一个依赖于 netifaces 的 pip3 包,但是当我第二天回来使用它时,包正在中断并报告错误网路。如果我尝试 运行 pip3 install netifaces 我会得到同样的错误:

~$ pip3 install netifaces
Collecting netifaces
  Using cached https://files.pythonhosted.org/packages/0d/18/fd6e9c71a35b67a73160ec80a49da63d1eed2d2055054cc2995714949132/netifaces-0.10.9.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 20, in <module>
        from setuptools.dist import Distribution, Feature
      File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 35, in <module>
        from setuptools.depends import Require
      File "/usr/lib/python3/dist-packages/setuptools/depends.py", line 7, in <module>
        from .py33compat import Bytecode
      File "/usr/lib/python3/dist-packages/setuptools/py33compat.py", line 55, in <module>
        unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
    AttributeError: 'HTMLParser' object has no attribute 'unescape'

HTMLParser().unescape 已在 Python 3.9 中删除。比较 the code in Python 3.8 vs Python 3.9.

该错误似乎是 setuptools 中的错误。尝试升级 setuptools。或者使用 Python 3.8.

我在PyCharm 2018年遇到这个问题。除了如上所述升级setuptools外,我还必须升级到PyCharm 2020.3.4才能解决这个问题。 PyCharm 问题跟踪器上的相关错误:https://youtrack.jetbrains.com/issue/PY-39579

希望这可以帮助人们避免花费数小时来调试它。

降级到任何较旧的 python3 版本都不是解决方案,大多数情况下升级安装工具无法解决问题。对我来说使用 python3.9 来处理 pip 的正确解决方案在 Ubuntu18 上如下: 找到 /usr/lib/python3/dist-packages/setuptools/py33compact.py33 并改变

# unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)  # comment out this line
unescape = getattr(html, 'unescape', None)
if unescape is None:
    # HTMLParser.unescape is deprecated since Python 3.4, and will be removed
    # from 3.9.
    unescape = html_parser.HTMLParser().unescape

我通过 deb 管理获得了 python3.6 和相关包。 副项目需要 python3.9 以及修复 pip 和 AttributeError: 'HTMLParser' object has no attribute 'unescape' 的解决方案 是为一个用户本地更新 python3.9 的 pip:

python3.9 -m pip install --upgrade pip

现在安装 python3.9 版本的 pip-packages 工作:

python3.9 -m pip install --target=~/.local/lib/python3.9/site-packages numpy