Python3.9上的pip3失败,错误信息为“HTMLParser”对象没有属性“unescape”。

63
安装完ubuntu的python3.9后,使用pip安装某些软件包时失败了:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 14, in <module>
        from setuptools.dist import Distribution, Feature
      File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 24, 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 54, in <module>
        unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
    AttributeError: 'HTMLParser' object has no attribute 'unescape'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

1
这些链接可能会有所帮助: https://github.com/coursera-dl/coursera-dl/issues/778 https://github.com/coursera-dl/edx-dl/commit/5490a99a98b56f544661c131229ef640ace2b064 - Guodong Hu
我在使用PyCharm创建新的venv时遇到了类似的问题。转而使用PowerShell解决了我的问题。 - hsc
如果我要猜的话,问题不在于shell,而是Python版本。你现在使用了不同的Python或者不同的环境(pip等)。 - borgr
1个回答

145

经过一些尝试和错误,我升级了pip、distlib和setuptools,问题得到了解决。不确定其中哪一个引起了问题。(在最后两个中,我发现了其他站点的12)

这是由于Python3.9中从HTMLParser中删除unescape引起的,这似乎破坏了setuptools。

pip3 install --upgrade setuptools

如果它不起作用,请尝试以下方法:

pip3 install --upgrade pip
pip3 install --upgrade distlib

来自@seb的评论:默认的pip3可能不是您正在使用的Python版本。如果是这样,请尝试使用您使用的特定版本的pip(例如pip3.9)。


1
对我来说有效!无论是distlib还是setuptools都可以为我完成。 - molecular
2
我尝试过了,我正在使用Pycharm IDE,但仍然出现错误。我已经更新了pycharm、setuptools和distlib。现在该怎么办? - Ankita Gupta
尝试从shell中运行,你是否在PyCharm的错误环境中运行?因此它并没有真正更新? - borgr
19
pip3 install 会使用默认的 Python3(通常是Python3.6),因此不能解决Python3.9的问题。正确的做法是通过以下命令进行安装: python3.9 -m pip install --upgrade pip - seb
1
这并不能解决错误。 - Cerin
显示剩余2条评论

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