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.

`ensurepip` fails with `importlib.metadata` backend

See original GitHub issue

Description

In Debian, we use the pip from our pip package with ensurepip. We’ve noticed with 3.11, and pip 22.1.1, ensurepip isn’t doing anything any more.

The relevant change is that the importlib.metadata is the default backend with Python 3.11. If we force it back to the pkg_resources backend, it works.

Expected behavior

ensurepip is expected to install pip. It doesn’t do anything, any more.

pip version

22.1.2+ dc7abcada7e263e80af6c8d4ea2147c067c78d01

Python version

3.11+ f9d0240db809fbb4443dc8f96a18e4c49af3fb7f

OS

Linux

How to Reproduce

  1. Install Python 3.11.
  2. Build / download a current (>= 22.1) pip wheel. Install it into ensurepip/_bundled/ in your Python installation.
  3. Update _PIP_VERSION in ensurepip/__init__.py to refer to the new version.
  4. python3.11 -m venv testve
  5. ls testve/lib/python3.11/site-packages/

This should not be empty, but will be.

For extra debugging:

  1. testve/bin/python -Im ensurepip --upgrade --default-pip -v

Output

Using pip 22.2.dev0 from /tmp/tmp3dhtsvpz/pip-22.2.dev0-py3-none-any.whl/pip (python 3.11)
Looking in links: /tmp/tmp3dhtsvpz
Requirement already satisfied: setuptools in ./tmp3dhtsvpz/setuptools-58.1.0-py3-none-any.whl (58.1.0)
Requirement already satisfied: pip in ./tmp3dhtsvpz/pip-22.2.dev0-py3-none-any.whl (22.2.dev0)

Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
pradyunsgcommented, Jun 30, 2022

Indeed, let’s do both then. 😃

1reaction
uranusjrcommented, Jun 12, 2022

Huh, pkg_resources explicitly ignores .dist-info in a wheel, but importlib.metadata does not:

https://github.com/pypa/pip/blob/dc7abcada7e263e80af6c8d4ea2147c067c78d01/src/pip/_vendor/pkg_resources/__init__.py#L1978-L1981

As you can tell from comment, the logic is pretty outdated and is arguably a bug, but this is relied by pip and “works”. I’ll work on a fix to do this properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ask Question - Stack Overflow
Failing that, try the same command with some extra verbosity : python3.9 -Im ensurepip --upgrade --default-pip -vvv and see what it is ...
Read more >
pip Changelog - pyup.io
using the ``importlib.metadata`` backend. ... Fix an issue where pip did not consider dependencies with and without extras to be equal (`9644 ...
Read more >
importlib — The implementation of import — Python 3.11.1 ...
importlib.metadata presents access to metadata from third-party distributions. ... If the loader inserted a module and the load fails, it must be removed...
Read more >
Changelog - pip documentation v22.3.1
The backend can be enabled on Python 3.10 and later by installing truststore ... Enable the importlib.metadata metadata implementation by default on Python ......
Read more >
Error: Command '['/path/to/env/bin/python3.7', '-Im', 'ensurepip ...
I am using python3.9. The command below solved the issue for me: sudo apt-get install python3.9-venv.
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 Reddit Thread

No results found

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