8

When trying to create new python 3.9 Virtualenv Environment in Pycharm I got such error

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'

What can be done with it?

9
  • 1: Which version of PyCharm? 2: You might want to update setuptools. Commented Jan 1, 2021 at 21:06
  • @Matthias - 1) 2019.2 2) Can you help me with this? Some instructions Commented Jan 1, 2021 at 21:17
  • A comment on this question stackoverflow.com/questions/17751439/… says that it is html.unescape in Python 3. So it looks like you are trying to execute Python 2 code in a Python 3 environment. Commented Jan 1, 2021 at 21:22
  • 1
    It works for me with PyCharm 2020.3 and setuptools 51.1.1. In your console you can update setuptools with pip install setuptools --upgrade. Commented Jan 1, 2021 at 21:33
  • 2
    @Headmaster I googled the error, the removal of HTMLParser().unescape from Python 3.9 caused an incompatibility with a specific version of setuptools, that is resolved by upgrading the versions. There are countless scenarios where this error can occur but the cause and solution is always the same - upgrade to the latest versions. (But you are right, I'm retracting my close vote because in this case PyCharm itself needs to be updated.) Commented Jan 2, 2021 at 8:16

3 Answers 3

8

Based on Matthias comment

To fix this error I have to update both pycharm (>=2020) and setuptools (>=41).

Hope this will help somebody

Sign up to request clarification or add additional context in comments.

1 Comment

For reference ticket PY-39579 on JetBrains.
5

Upgrading to a newer version of PyCharm/IntelliJ should solve the issue but if you have to use an older version of the IDE (<= 2019) with Python 3.9, then you can also resolve this issue by selecting the Inherit global site-packages option when creating your virtual environment. However, keep in mind that all of your global site-packages will be included in your new environment as a result.

If the error still persists, you may have to install/upgrade setuptools, pip, and distlib in your global site-packages like so,

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

where pip can be replaced with pip3, pip3.9, etc. as needed, and then try creating a virtual environment again with the Inherit global site-packages option selected.

1 Comment

was the setuptools for me. Other posts were missing that
3

you can use

import html
html.unescape

to replace

import HTMLParser
HTMLParser.HTMLParser().unescape

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.