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

11

我在AWS EC2上设置了一个新的Debian 10(Buster)实例,并能够安装一个依赖于netifaces的pip3包,但当我第二天回来时,这个软件包报告了一个netifaces错误导致它无法正常工作。如果我尝试运行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'
4个回答

17

HTMLParser().unescape已在Python 3.9中移除。请比较Python 3.8的代码Python 3.9的代码

错误似乎是setuptools中的一个错误。尝试升级setuptools,或使用Python 3.8。


7
太好了!pip3 install --upgrade setuptools 解决了所有问题。 - kodi
1
谢谢!我还需要升级pip来解决问题:python3 -m pip install --upgrade setuptools pip - Nicolas

2

我之前使用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包,如下:

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

2
我在PyCharm 2018中遇到了这个问题。除了如上所述升级setuptools之外,我还必须升级到PyCharm 2020.3.4来解决此问题。相关的PyCharm问题跟踪器错误: https://youtrack.jetbrains.com/issue/PY-39579 希望这可以帮助某些人避免花费数小时来尝试调试此问题。

1
降级到任何较旧的Python3版本并不是解决办法,大多数情况下升级setuptools也无法解决问题。对我来说,在Ubuntu18上使用pip使用python3.9的正确解决方案如下: locate /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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接