I setup a new Debian 10 (Buster) instance on AWS EC2, and was able to install a pip3 package that depended on netifaces, but when I came back to it the next day the package is breaking reporting an error in netifaces. If I try to run pip3 install netifaces I get the same error:
~$ pip3 install netifaces
Collecting netifaces
Using cached https://files.pythonhosted.org/packages/0d/18/fd6e9c71a35b67a73160ec80a49da63d1eed2d2055054cc2995714949132/netifaces-0.10.9.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 20, in <module>
from setuptools.dist import Distribution, Feature
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 35, 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 55, in <module>
unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
AttributeError: 'HTMLParser' object has no attribute 'unescape'
HTMLParser().unescape was removed in Python 3.9. Compare the code in Python 3.8 vs Python 3.9.
The error seems to be a bug in setuptools. Try to upgrade setuptools. Or use Python 3.8.
I was facing this issue in PyCharm 2018. Apart from upgrading setuptools as mentioned above, I also had to upgrade to PyCharm 2020.3.4 to solve this issue. Related bug on PyCharm issue tracker: https://youtrack.jetbrains.com/issue/PY-39579
Hope this helps someone avoid spending hours trying to debug this.
I had python3.6 and related packages through deb management.
Needed python3.9 for side project and the solution to fix pip and AttributeError: 'HTMLParser' object has no attribute 'unescape'
was to update pip for python3.9 locally for one user:
python3.9 -m pip install --upgrade pip
now installing python3.9 version of the pip-packages work:
python3.9 -m pip install --target=~/.local/lib/python3.9/site-packages numpy
Downgrading to any older python3 version is not the solution and most of the time upgrading setuptools won't fix the issue. The proper solution that worked for me to work with pip using python3.9 is the following on Ubuntu18:
locate /usr/lib/python3/dist-packages/setuptools/py33compact.py33
and change
# unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape) # comment out this line
unescape = getattr(html, 'unescape', None)
if unescape is None:
# HTMLParser.unescape is deprecated since Python 3.4, and will be removed
# from 3.9.
unescape = html_parser.HTMLParser().unescape
Related
Trying to install pip without internet, so I downloaded the tar.gz package from pypi.org and when installing the pip setup file by running "python setup.py install" I get "No Module Named 'Setuptools'".
So I downloaded setuptools.tar.gz from pypi.org and ran the "python setup.py install" but this time I get a syntax error. Python version running is 3.5.2.
Traceback (most recent call last):
File "setup.py", line 7, in <module>
import setuptools
File "/home/insite/setuptools-57.0.0/setuptools/__init__.py", line 18, in <module>
from setuptools.dist import Distribution
File "/home/insite/setuptools-57.0.0/setuptools/dist.py", line 585
license_files: Optional[List[str]] = self.metadata.license_files
^
SyntaxError: invalid syntax
It looks like you're trying to install setuptools 57.0.0 on Python 3.5. As of setuptools 51.0.0,
Breaking Changes
#2435: Require Python 3.6 or later.
You need a version of setuptools that's 50.0.0 or older.
For what it's worth, the specific error you're getting is because of PEP 526, which was added to Python officially in 3.6. But even if you patched that somehow (and I don't recommend trying), you're likely to run into other problems. You just need an older setuptools or a newer Python.
Wrong setuptools version was used. Python 3.5 uses setuptools version 50.0.0 or older. Thanks to Silvio Mayolo.
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?
Based on Matthias comment
To fix this error I have to update both pycharm (>=2020) and setuptools (>=41).
Hope this will help somebody
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.
you can use
import html
html.unescape
to replace
import HTMLParser
HTMLParser.HTMLParser().unescape
I've just upgraded to Fedora 27, and have been unable to get psycopg2 working.
I'd very much appreciate any help anyone can provide.
As a simple test case, I've been executing
>>> import psycopg2
at the interactive shell. This works fine for Python 2.7, but fails for Python 3.x.
With Python 3.4 and 3.5, I get the message:
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'psycopg2'
With Python 3.6, I see:
Traceback (most recent call last):
File "", line 1, in
File "/home/jazcap53/.local/lib/python3.6/site-packages/psycopg2/init.py", line 50, in
from psycopg2._psycopg import ( # noqa
ImportError: /home/jazcap53/.local/lib/python3.6/site-packages/psycopg2/.libs/libresolv-2-c4c53def.5.so: symbol __res_maybe_init, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference
I installed Fedora 27 from DVD-ROM. I find psycopg2 packages located at
/usr/lib64/python2.7/site-packages
and
/home/jazcap53/.local/lib/python3.6/site-packages
My Python packages were all either included with Fedora, or installed via dnf. They are:
python3-3.6.3-2.fc27.x86_64
python35-3.5.4-1.fc27.x86_64
python34-3.4.7-1.fc27.x86_64
python2-2.7.14-2.fc27.x86_64
Some packages I have installed that may be relevant are:
python2-devel-2.7.14-2.fc27.x86_64
python3-devel-3.6.3-2.fc27.x86_64
libpqxx-1:5.0.1-2.f27.x86_64
libpqxx-devel-1:5.0.1-2.f27.x86_64
libgcc-7.2.1-2.fc27.x86_64
postgresql-devel-9.6.6-1.fc27.x86_64
P.S.: If I'm asking this question in the wrong place, please direct me to the right place.
Edit:
I noticed that:
/usr/lib64/python2.7/site-packages/
contains subdirectories
psycopg2 and
psycopg2-2.7.3-py2.7.egg-info
but
/usr/lib64/python3.4/site-packages/ and
/usr/lib64/python3.5/site-packages/
contain nothing related to psycopg2
and
/usr/lib64/python3.6/site-packages/
contains subdirectory
psycopg2-2.7.3-py3.6.egg-info
but not psycopg2 itself
As you may have noticed, each version of Python has its own package hierarchy. So the installation on Python 3.6 will not give you access on 3.4 and 3.5.
With that said, there seems to be some problem with the system's standard lib with Python 3.6. One solution to that could be to install without binaries, like this:
python3.6 -m pip uninstall psycopg2
python3.6 -m pip install --no-binary :all: psycopg2
To install psycopg2 on 3.4 and 3.5 you would run these with or without the --no-binary option:
python3.4 -m pip install psycopg2
python3.5 -m pip install psycopg2
If you have automatic installs / docker install you need to ensure you add the following line to requirements.txt to ensure psycopg2 installs from source, rather than using the binary, or you'll continue to experience the above issue upon deployment.
psycopg2>=2.7,<2.8 --no-binary psycopg2
After updating a package (IPython in my case) using pip install -U ipython running any Python script that uses entry points fails with this error:
Traceback (most recent call last):
File "/home/adrian/dev/indico/env/bin/indico", line 5, in <module>
from pkg_resources import load_entry_point
...
File "/home/adrian/dev/indico/env/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 94, in __init__
requirement_string[e.loc:e.loc + 8], requirement_string))
pkg_resources._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'< 2.0'"
Nothing else changed, I did not update any other libraries.
This is caused by an issue in setuptools==20.2.1 which is pulled in by IPython (setuptools>..), so a pip install -U updated it.
Until a fixed version is released or the broken version is pulled from PyPI there is a simple workaround (but note that it will break again if something updates setuptools):
pip install -U pip
pip uninstall setuptools
pip install 'setuptools<20.2'
The pip update is needed since older versions of pip will not work without setuptools being installed
See these IRC logs and BitBucket issue for details:
http://chat-logs.dcpython.org/day/pypa/2016-02-25
https://bitbucket.org/pypa/setuptools/issues/502/packaging-164-does-not-allow-whitepace
Try downgrading your pip to 8.1.1:
pip install pip==8.1.1
That solved it for me.
In my case I had package = "2.8.0" in my Pipfile. Changing it to package = "==2.8.0" fixed this error for me.
I am using Python 2.7.4. Works fine for web development and everything that doesn't require the use of specific packages.
But every time I am trying to install and use a new package, I get an error.
Example:
Cloned https://github.com/fatiherikli/worldcup
install worldcup was successful (python-dateutil, colorama, pytz, humanize)
But
$ worldcup today
Traceback (most recent call last):
File "/usr/local/bin/worldcup", line 8, in <module>
load_entry_point('worldcup==1.0.3', 'console_scripts', 'worldcup')()
File "/Library/Python/2.6/site-packages/worldcup.py", line 129, in main
print prettify(match)
File "/Library/Python/2.6/site-packages/worldcup.py", line 45, in prettify
seconds = diff.total_seconds()
AttributeError: 'datetime.timedelta' object has no attribute 'total_seconds'
My python version is 2.7 not 2.6:
$ python --version
Python 2.7.4
Any suggestion?
From the path names it appears you are running on a version of Mac OS X, which comes with multiple builtin versions of Python and you have likely installed a newer version of Python 2.7. Chances are you have installed a version of pip for your system Python 2.6 but not for the Python 2.7 that worldcup requires. You can easily check this by typing:
python2.7 -m pip install worldcup
If pip is not available for that instance of Python you'll need to install it by downloading get-pip.py and running it with python2.7.