`ensurepip` fails with `importlib.metadata` backend
See original GitHub issueDescription
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
- Install Python 3.11.
- Build / download a current (>= 22.1) pip wheel. Install it into
ensurepip/_bundled/in your Python installation. - Update
_PIP_VERSIONinensurepip/__init__.pyto refer to the new version. python3.11 -m venv testvels testve/lib/python3.11/site-packages/
This should not be empty, but will be.
For extra debugging:
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
- I agree to follow the PSF Code of Conduct.
Issue Analytics
- State:
- Created a year ago
- Comments:14 (14 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Indeed, let’s do both then. 😃
Huh,
pkg_resourcesexplicitly ignores.dist-infoin a wheel, butimportlib.metadatadoes 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.