AttributeError: module 'html5lib.treebuilders.etree' has no attribute 'getETreeModule' - python

Suggestions please, thanks :)
pip list --outdated --format=freeze
Gives the following error:
ERROR: Exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 223, in _main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/_internal/commands/list.py", line 175, in run
packages = self.get_outdated(packages, options)
File "/usr/lib/python3/dist-packages/pip/_internal/commands/list.py", line 184, in get_outdated
return [
File "/usr/lib/python3/dist-packages/pip/_internal/commands/list.py", line 184, in <listcomp>
return [
File "/usr/lib/python3/dist-packages/pip/_internal/commands/list.py", line 237, in iter_packages_latest_infos
for dist in map_multithread(latest_info, packages):
File "/usr/lib/python3.9/multiprocessing/pool.py", line 870, in next
raise value
File "/usr/lib/python3.9/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3/dist-packages/pip/_internal/commands/list.py", line 214, in latest_info
all_candidates = finder.find_all_candidates(dist.key)
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 825, in find_all_candidates
package_links = self.process_project_url(
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 793, in process_project_url
page_links = list(parse_links(html_page))
File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 324, in wrapper_wrapper
return list(fn(page))
File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 335, in parse_links
document = html5lib.parse(
File "/usr/share/python-wheels/html5lib-1.1-py2.py3-none-any.whl/html5lib/html5parser.py", line 44, in parse
tb = treebuilders.getTreeBuilder(treebuilder)
File "/usr/share/python-wheels/html5lib-1.1-py2.py3-none-any.whl/html5lib/treebuilders/__init__.py", line 85, in getTreeBuilder
return etree.getETreeModule(implementation, **kwargs).TreeBuilder
AttributeError: module 'html5lib.treebuilders.etree' has no attribute 'getETreeModule'

I solved this problem updating pip, i updated from pip 20.3.4 to 21.3
so just type:
pip install pip -U
Seems like there is some bug in pip itself.

I've done some analysis of this bug in in the Debian bugtracker.
It appears to be a race-condition triggered by the way Debian was packaging pip until recently. Dependencies were zipimported from wheels instead of vendored in the source tree, as upstream does.
This should already be resolved in Debian >= 12 (bookworm) and Ubuntu >= 22.04 (jammy).
An updated for pip in Debian 11 (bullseye) is in progress.

Not a fix, but a solution of sorts:
I 'fixed' this by updating every package.
for f in `pip list | tail -n +3 | cut -d' ' -f1`; do
pip install --update "$f";
done
I found OP's problem while logged-in as root and immediately after upgrading to Debian 11; dunno if that's significant.

Related

pip3 error : AttributeError: module 'platform' has no attribute 'linux_distribution'? (ubuntu 20.04 with python 3.8)

I think i have messed up some python files when installing some packages in a requirement.txt file
now i get these errors when trying to install or uninstall anything:
for example when trying to uninstall matplotlib without sudo using pip3 uninstall matplotlib (even tho i never had to use sudo to uninstall anything before) :
Found existing installation: matplotlib 3.3.1
Uninstalling matplotlib-3.3.1:
Would remove:
/usr/local/lib/python3.8/dist-packages/matplotlib-3.3.1-py3.8-linux-x86_64.egg
Proceed (y/n)? y
ERROR: Exception:
Traceback (most recent call last):
File "/usr/lib/python3.8/shutil.py", line 788, in move
os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.8/dist-packages/matplotlib-3.3.1-py3.8-linux-x86_64.egg' -> '/tmp/pip-uninstall-nw393b36'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/john/.local/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 228, in _main
status = self.run(options, args)
File "/home/john/.local/lib/python3.8/site-packages/pip/_internal/commands/uninstall.py", line 89, in run
uninstall_pathset = req.uninstall(
File "/home/john/.local/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 686, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File "/home/john/.local/lib/python3.8/site-packages/pip/_internal/req/req_uninstall.py", line 394, in remove
moved.stash(path)
File "/home/john/.local/lib/python3.8/site-packages/pip/_internal/req/req_uninstall.py", line 283, in stash
renames(path, new_path)
File "/home/john/.local/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 352, in renames
shutil.move(old, new)
File "/usr/lib/python3.8/shutil.py", line 800, in move
rmtree(src)
File "/usr/lib/python3.8/shutil.py", line 715, in rmtree
_rmtree_safe_fd(fd, path, onerror)
File "/usr/lib/python3.8/shutil.py", line 672, in _rmtree_safe_fd
onerror(os.unlink, fullname, sys.exc_info())
File "/usr/lib/python3.8/shutil.py", line 670, in _rmtree_safe_fd
os.unlink(entry.name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: 'pylab.py'
When trying with sudo :
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/usr/local/lib/python3.8/dist-packages/pip/commands/uninstall.py", line 46, in run
with self._build_session(options) as session:
File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 66, in _build_session
session = PipSession(
File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 321, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 93, in user_agent
zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 33, in <module>
sys.exit(load_entry_point('pip==20.3.dev0', 'console_scripts', 'pip3')())
File "/usr/local/lib/python3.8/dist-packages/pip/__init__.py", line 217, in main
return command.main(cmd_args)
File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 242, in main
with self._build_session(
File "/usr/local/lib/python3.8/dist-packages/pip/basecommand.py", line 66, in _build_session
session = PipSession(
File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 321, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/lib/python3.8/dist-packages/pip/download.py", line 93, in user_agent
zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'
How can i fix this? i am using ubuntu 20.04 and i heard uninstalling python3.8 is a big no no since many system files use it, so what should i do?
tried many suggestion on similar questions like this and it didn't work:
How to fix "module 'platform' has no attribute 'linux_distribution'" when installing new packages with Python3.8?
Python 3.8 removed some stuff. I solved my problems with pip (specifically pip install) by installing pip with curl
What worked for me was:
cd ~/Downloads
Downloading get-pip.py
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then running it with python 3.8:
python3.8 get-pip.py
Solved it for me.

How to build dev version of python datatable on macos (getting pip._vendor.pep517.wrappers.BackendUnavailable)

Following the directions on the datatable page https://datatable.readthedocs.io/en/latest/install.html
So I ran this:
$pip3 install git+https://github.com/h2oai/datatable
The result is :
Collecting git+https://github.com/h2oai/datatable
Cloning https://github.com/h2oai/datatable to /private/var/folders/d6/m67jyndd7h754m3810cl3bpm0000gp/T/pip-req-build-hv991zd2
Running command git clone -q https://github.com/h2oai/datatable /private/var/folders/d6/m67jyndd7h754m3810cl3bpm0000gp/T/pip-req-build-hv991zd2
Getting requirements to build wheel ... done
ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 178, in main
status = self.run(options, args)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 352, in run
resolver.resolve(requirement_set)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolve.py", line 131, in resolve
self._resolve_one(requirement_set, req)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolve.py", line 294, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/resolve.py", line 242, in _get_abstract_dist_for
self.require_hashes
File "/usr/local/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 362, in prepare_linked_requirement
abstract_dist.prep_for_dist(finder, self.build_isolation)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 169, in prep_for_dist
self.install_backend_dependencies(finder=finder)
File "/usr/local/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 123, in install_backend_dependencies
reqs = req.pep517_backend.get_requires_for_build_wheel()
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py", line 71, in get_requires_for_build_wheel
'config_settings': config_settings
File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py", line 162, in _call_hook
raise BackendUnavailable
pip._vendor.pep517.wrappers.BackendUnavailable
This is not actionable for me: I'm not certain what to fix/ how to proceed. Hints?
Note: in the meantime I have installed version 0.10.1 as follows:
sudo pip3 install 'datatable==0.10.1'
This has important by (expression based groupby) and sortvalues() that I need
Most likely this error occurs because you're trying to build datatable using an old version of pip. In order to build datatable from source, pip version 20.0 or higher is required.
Unfortunately, there is no way for a project to specify that it needs a specific minimum version of pip. And I presume if such setting would eventually be added, only the newest versions of pip would know about it anyways, defeating the purpose.

Why when installing any package through pip3, the configparser.InterpolationSyntaxError error occurs?

When I install any package through pip3 for python 3.7.4 an error occurs in the form:
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 179, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 393, in run
use_user_site=options.use_user_site,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/req/__init__.py", line 57, in install_given_reqs
**kwargs
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/req/req_install.py", line 913, in install
use_user_site=use_user_site, pycompile=pycompile,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/req/req_install.py", line 445, in move_wheel_files
warn_script_location=warn_script_location,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/wheel.py", line 320, in move_wheel_files
prefix=prefix,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/locations.py", line 166, in distutils_scheme
d.parse_config_files()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 413, in parse_config_files
val = parser.get(section,opt)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 799, in get
d)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 394, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/configparser.py", line 444, in _interpolate_some
"found: %r" % (rest,))
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%Y-%m-%d %H:%M:%S'
I didn’t have this before. This problem has appeared recently. The problem occurs on OS X Mojave version 10.14.6
Check your current working directory for a setup.cfg file with unsupported syntax in it.
This is open issue #5182 CLI parses unrelated config files and then crashes, created by me in April 2018.
As a workaround until the issue is fixed, you can cd into a different directory and try installing again.

Running flake8 gives - AttributeError: 'OptionManager' object has no attribute 'config_options'

I installed flake8 using the following command.
pip3 install flake8
Executing flake8 from terminal gives the following error.
Traceback (most recent call last):
File "/home/bilesh/.local/bin/flake8", line 11, in <module>
sys.exit(main())
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/main/cli.py", line 18, in main
app.run(argv)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/main/application.py", line 394, in run
self._run(argv)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/main/application.py", line 381, in _run
self.initialize(argv)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/main/application.py", line 365, in initialize
self.register_plugin_options()
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/main/application.py", line 206, in register_plugin_options
self.check_plugins.register_options(self.option_manager)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 496, in register_options
list(self.manager.map(register_and_enable))
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 302, in map
yield func(self.plugins[name], *args, **kwargs)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 492, in register_and_enable
call_register_options(plugin)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 404, in generated_function
return method(optmanager, *args, **kwargs)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 221, in register_options
add_options(optmanager)
File "/home/bilesh/.local/lib/python3.6/site-packages/flake8/_pyflakes.py", line 79, in add_options
parser.config_options.extend(['builtins', 'doctests',
AttributeError: 'OptionManager' object has no attribute 'config_options'
Found the following bug from 2016 but it seems to have been fixed.
https://github.com/PyCQA/flake8-import-order/issues/79
Not sure if I'm doing anything wrong here. Any help will be appreciated.
$ pip3 freeze | grep flake8
flake8==3.7.7
flake8-docstrings==1.3.0
flake8-polyfill==1.0.2
So, as per the comment posted by phd on this question, I did the following things.
Uninstall flake8: pip3 uninstall flake8
Clean directories: sudo rm -R /path/to/directory/flake8
Reinstall flake8: pip3 install flake8
And it worked :)

libgfortran not found when installing scipy using enthought canopy

I am trying to install scipy using enpkg in Enthought Canopy but I am getting this error:
(canopy_env) server 17:10:33 ~ $ enpkg scipy
prefix: /home/user/apps/canopy_env
Traceback (most recent call last):
File "/home/user/apps/canopy_env/bin/enpkg", line 10, in <module>
sys.exit(main())
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/main.py", line 746, in main
install_req(enpkg, req, args) # install (default)
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/main.py", line 395, in install_req
_perform_install()
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/main.py", line 311, in _perform_install
enpkg.execute(actions)
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/enpkg.py", line 279, in execute
self.fetch(egg, force=int(opcode[-1]))
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/enpkg.py", line 455, in fetch
f.fetch_egg(egg, force, self._execution_aborted)
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/fetch.py", line 147, in fetch_egg
self.fetch(egg, execution_aborted)
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/fetch.py", line 30, in fetch
fi, info = self.remote.get(key)
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/store/indexed.py", line 47, in get
return self.get_data(key), self.get_metadata(key)
File "/home/user/apps/Canopy/appdata/canopy-1.1.0.1371.rh5-x86_64/lib/python2.7/site-packages/enstaller/store/indexed.py", line 136, in get_data
raise KeyError("%s: %s" % (e, url))
KeyError: u'HTTP Error 404: NOT FOUND: https://api.enthought.com/eggs/rh5-64/libgfortran-3.0.0-1.egg'
I am using Canopy Express and this package is provided (see this)..
I have tried to install it from pip but, since I have not administration permissions, I am unable to install it..
Edit: the same happens with Pygments package when installing ipython:
appinst-2.1.2-1.egg [fetching]
55 KB [.................................................................]
MarkupSafe-0.18-2.egg [fetching]
26 KB [.................................................................]
...
KeyError: u'HTTP Error 404: NOT FOUND: https://api.enthought.com/eggs/rh5-64/Pygments-1.6.0-1.egg'
Thanks
a few of our free packages had been flagged as "commercial" by mistake. We fixed the problem and you should be able to install them now.
Sorry about the trouble!

Categories

Resources