Python 3.9 和 Pycharm、HTMLParser AttributeError

当尝试在 Pycharm 中创建新的 python 3.9 Virtualenv 环境时,我收到了这样的错误

AttributeError: 'HTMLParser' object has no attribute 'unescape'

Traceback (most recent call last):
  File "/var/folders/6g/vnvmvlf51gv49m22rzj9zdtw0000gn/T/tmpifdsjw6lpycharm-management/setuptools-40.8.0/setup.py", line 11, in <module>
    import setuptools
  File "/private/var/folders/6g/vnvmvlf51gv49m22rzj9zdtw0000gn/T/tmpifdsjw6lpycharm-management/setuptools-40.8.0/setuptools/__init__.py", line 20, in <module>
    from setuptools.dist import Distribution, Feature
  File "/private/var/folders/6g/vnvmvlf51gv49m22rzj9zdtw0000gn/T/tmpifdsjw6lpycharm-management/setuptools-40.8.0/setuptools/dist.py", line 35, in <module>
    from setuptools.depends import Require
  File "/private/var/folders/6g/vnvmvlf51gv49m22rzj9zdtw0000gn/T/tmpifdsjw6lpycharm-management/setuptools-40.8.0/setuptools/depends.py", line 7, in <module>
    from .py33compat import Bytecode
  File "/private/var/folders/6g/vnvmvlf51gv49m22rzj9zdtw0000gn/T/tmpifdsjw6lpycharm-management/setuptools-40.8.0/setuptools/py33compat.py", line 55, in <module>
    unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
AttributeError: 'HTMLParser' object has no attribute 'unescape'

可以用它做什么?

stack overflow Python 3.9 and Pycharm, HTMLParser AttributeError
原文答案
author avatar

接受的答案

基于 Matthias 评论

要修复此错误,我必须同时更新 pycharm (>=2020) 和 setuptools (>=41)。

希望这会对某人有所帮助


答案:

作者头像

您可以使用

import html
html.unescape

取代

import HTMLParser
HTMLParser.HTMLParser().unescape
作者头像

升级到Pycharm/Intellij的较新版本应该解决该问题,但是如果您必须使用Python 3.9使用旧版本的IDE(<= 2019),那么您还可以通过选择“ sastarit Global site-”来解决此问题。包装**创建虚拟环境时的选项。但是,请记住,因此,您的所有全球站点包都将在您的新环境中包含在您的新环境中。

如果错误仍然存在,则可能必须在您的全局站点包中安装/升级setuptoop,pip和distlib,这样,

pip install --upgrade setuptools
pip install --upgrade pip
pip install --upgrade distlib

其中 pip 可以根据需要代替 pip3pip3.9 等。