pip3 on python3.9 fails on 'HTMLParser' object has no attribute 'unescape' [duplicate]
Asked Answered
H

1

64

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.
Hazelhazelnut answered 9/1, 2021 at 7:49 Comment(3)
github.com/coursera-dl/coursera-dl/issues/778 github.com/coursera-dl/edx-dl/commit/… may helpMarilee
I encounter similar issue while using pycharm to create a new venv. Switch to using powershell fixed my issue.Complementary
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.Hazelhazelnut
H
146

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)

Hazelhazelnut answered 9/1, 2021 at 7:49 Comment(7)
works for me! Either distlib or setuptools did it for me.Specular
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?Disturbed
Try running from the shell, is it possible you run from the wrong environment in pycharm? So it is not really updated?Hazelhazelnut
pip3 install --upgrade pip pip3 install --upgrade distlib Works for me!!!!Lavish
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 pipIleac
This does not fix the error.Anderton
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.Stressful

© 2022 - 2024 — McMap. All rights reserved.