63

After installing (ubuntu) python3.9, installing some packages with pip failes on:

    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.
borgr
  • 20,175
  • 6
  • 25
  • 35
  • 1
    https://github.com/coursera-dl/coursera-dl/issues/778 https://github.com/coursera-dl/edx-dl/commit/5490a99a98b56f544661c131229ef640ace2b064 may help – Guodong Hu May 08 '21 at 03:57
  • I encounter similar issue while using pycharm to create a new venv. Switch to using powershell fixed my issue. – hsc Aug 25 '22 at 10:20
  • If I have to guess, it is not the shell but the python version, you use a different python or different environment (pip etc.) now that you switched. – borgr Aug 26 '22 at 04:16

1 Answers1

144

After some trial and error I upgraded, pip, distlib and setuptools and it solved it. Not sure which of those is causing it. (On the last two I found issues 1 2 of other sites) It is caused by removing unescape from HTMLParser in python3.9, which seems to break setuptools.

pip3 install --upgrade setuptools

If it does not work, try also:

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

Note from @seb comment: The default pip3 may not be the python you are using. If so, try pip of your specific version used (e.g. pip3.9)

borgr
  • 20,175
  • 6
  • 25
  • 35
  • 1
    works for me! Either distlib or setuptools did it for me. – molecular Jan 10 '21 at 10:49
  • 2
    I tried this, I am using Pycharm IDE but still this is raising an error. I have updated pycharm , setuptools and distlib. What do I do now? – Ankita Gupta Mar 04 '21 at 14:12
  • Try running from the shell, is it possible you run from the wrong environment in pycharm? So it is not really updated? – borgr Mar 05 '21 at 15:45
  • pip3 install --upgrade pip pip3 install --upgrade distlib Works for me!!!! – matabares Jun 04 '21 at 09:01
  • 19
    pip3 install was using default python3 for me (python3.6), so it didn't solve the issue for python3.9. This is what worked: python3.9 -m pip install --upgrade pip – seb Jun 21 '21 at 13:35
  • 1
    This does not fix the error. – Cerin Aug 17 '22 at 19:48
  • This solution should work up to version 3.9. But from version 3.10 it doesn't work anymore. In this case, just import the `html` package and simply do `html.unescape`. – Pereira Jun 22 '23 at 15:28