question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to install anything using pip due to TypeError

See original GitHub issue

Description

I am unable to install any packages from PyPi using pip because I keep getting an error.

Expected behavior

I’d expect pip to be able to install packages without any errors.

pip version

20.3.4

Python version

3.10.1

OS

Arch Linux

How to Reproduce

  1. Run pip install --user pywhat

In the example, I am using pywhat as the package but I get the errors shown in the Output section when installing any package.

Output

ERROR: Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 223, in _main
    status = self.run(options, args)
  File "/usr/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 180, in wrapper
    return func(self, options, args)
  File "/usr/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 320, in run
    requirement_set = resolver.resolve(
  File "/usr/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 121, in resolve
    self._result = resolver.resolve(
  File "/usr/lib/python3.10/site-packages/resolvelib/resolvers.py", line 454, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/usr/lib/python3.10/site-packages/resolvelib/resolvers.py", line 319, in resolve
    name, crit = self._merge_into_criterion(r, parent=None)
  File "/usr/lib/python3.10/site-packages/resolvelib/resolvers.py", line 176, in _merge_into_criterion
    crit = Criterion.from_requirement(self._p, requirement, parent)
  File "/usr/lib/python3.10/site-packages/resolvelib/resolvers.py", line 83, in from_requirement
    if not cands:
  File "/usr/lib/python3.10/site-packages/resolvelib/structs.py", line 124, in __bool__
    return bool(self._sequence)
  File "/usr/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 99, in __bool__
    return any(self)
  File "/usr/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 220, in iter_index_candidates
    result = self._finder.find_best_candidate(
  File "/usr/lib/python3.10/site-packages/pip/_internal/index/package_finder.py", line 882, in find_best_candidate
    candidates = self.find_all_candidates(project_name)
  File "/usr/lib/python3.10/site-packages/pip/_internal/index/package_finder.py", line 825, in find_all_candidates
    package_links = self.process_project_url(
  File "/usr/lib/python3.10/site-packages/pip/_internal/index/package_finder.py", line 789, in process_project_url
    html_page = self._link_collector.fetch_page(project_url)
  File "/usr/lib/python3.10/site-packages/pip/_internal/index/collector.py", line 618, in fetch_page
    return _get_html_page(location, session=self.session)
  File "/usr/lib/python3.10/site-packages/pip/_internal/index/collector.py", line 430, in _get_html_page
    resp = _get_html_response(url, session=session)
  File "/usr/lib/python3.10/site-packages/pip/_internal/index/collector.py", line 127, in _get_html_response
    resp = session.get(
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3.10/site-packages/pip/_internal/network/session.py", line 428, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 697, in send
    r.content
  File "/usr/lib/python3.10/site-packages/requests/models.py", line 836, in content
    self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
  File "/usr/lib/python3.10/site-packages/requests/models.py", line 758, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "/usr/lib/python3.10/site-packages/urllib3/response.py", line 579, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/usr/lib/python3.10/site-packages/urllib3/response.py", line 522, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/home/siddharth/.local/lib/python3.10/site-packages/cachecontrol/filewrapper.py", line 96, in read
    self._close()
  File "/home/siddharth/.local/lib/python3.10/site-packages/cachecontrol/filewrapper.py", line 76, in _close
    self.__callback(result)
  File "/home/siddharth/.local/lib/python3.10/site-packages/cachecontrol/controller.py", line 329, in cache_response
    self.cache.set(
TypeError: SafeFileCache.set() got an unexpected keyword argument 'expires'

Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
pradyunsgcommented, Dec 26, 2021

EndeavourOS is an Arch Linux based Linux distribution.

Yea, this could be a bug with how Arch Linux has repackaged pip. /cc @FFY00, who is involved on their end, I believe. This might be another report related to debundling.

If it’s indeed a bug on the Arch side… reminder about how you’re creating additional work for upstream. 😃


To recover, what you can do is:

  • download get-pip.py, from bootstrap.pypa.io/get-pip.py
  • run it with the Python installation that you have, that’s been borked by Arch Linux’s meddling with pip. That should be python3.10 /path/to/get-pip.py
  • It will download a functional version of pip, uninstall the broken version (I think this should “just work”) and install functional pip version.
0reactions
Ivozcommented, Jan 4, 2022

To be clear about the issue, you can see in the error log:

File “/usr/lib/python3.10/site-packages/urllib3/response.py”, line 522, in read data = self._fp.read(amt) if not fp_closed else b"" File “/home/siddharth/.local/lib/python3.10/site-packages/cachecontrol/filewrapper.py”, line 96, in read self._close()

That the module imports suddenly jump from system files under /usr/lib/python3.10/site-packages to user-installed files under /home/siddharth/.local/lib/. So pip is now attemping to use code that is installed separately from itself.

When this happens, it is POSSIBLE for things to keep working but also very possible for things to just suddenly break ala this issue. Likely because you have installed an incompatible version of cachecontrol globally.

Pip BY DEFAULT is configured to never allow this to happen; it will only import vendored packages local to itself (therefore, could never get an incompatible version of cachecontrol).

Linux distros are disgusted by the very concept of vendoring, and so pip in an attempt to be a “good FOSS neighbour” allows them a couple of mechanisms to de-vendor pip’s internal packages, in the name of “if we can update all packages separately then there is less likely to be a vendored package with a security hole”.

However when they enable these mechanisms they also allow this sort of breakage to occur.

In general, try not to touch your system python with anything but your system package manager, and use virtualenv’s / the venv module instead to isolate yourself while installing pypi packages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pip install resulting in a TypeError - Stack Overflow
pip install poetry returns the following: Collecting poetry Downloading poetry-1.1.13-py2.py3-none-any.whl (175 kB) ...
Read more >
Unable to install modules through pip due to TypeError after ...
Hey, I'm unfortunately unable to install any packages through pip due a strange error I got after updating my Arch Linux system.
Read more >
Changelog - pip documentation v22.3.1
Fix pip install issues using a proxy due to an inconsistency in how Requests is currently handling variable precedence in session. (#9691) ...
Read more >
How to Install Pip on Windows - ActiveState
One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot...
Read more >
Build and install error messages - TensorFlow
38896424 31058, "No matching distribution found for tensorflow": Pip can't find a TensorFlow package compatible with your system. Check the system requirements ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found