Python 3.9 and Pycharm, HTMLParser AttributeError

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?


Solution 1:

Based on Matthias comment

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

Hope this will help somebody

Solution 2:

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.