upgrade from 22.2 to 22.2.1. fails with ImportError for name '_distutils'
See original GitHub issueDescription
When trying to upgrade from 22.2 to 22.2.1, the install fails because of an ImportError. The setuptools version is 63.2.0.
Traceback (most recent call last):
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
return func(self, options, args)
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/commands/install.py", line 461, in run
installed = install_given_reqs(
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/req/__init__.py", line 73, in install_given_reqs
requirement.install(
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/req/req_install.py", line 752, in install
scheme = get_scheme(
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/locations/__init__.py", line 244, in get_scheme
from . import _distutils
ImportError: cannot import name '_distutils' from 'pip._internal.locations' (/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/locations/__init__.py)
Expected behavior
Pip should be upgraded from 22.2 to 22.2.1
pip version
22.2
Python version
3.9.13
OS
macOS 10.15.7
How to Reproduce
With version 22.2 user-installed:
python3 -m pip install --user --upgrade pip
Output
% python3 -m pip install --user --upgrade pip
Requirement already satisfied: pip in ./Library/Python/3.9/lib/python/site-packages (22.2)
Collecting pip
Using cached pip-22.2.1-py3-none-any.whl (2.0 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.2
Uninstalling pip-22.2:
Successfully uninstalled pip-22.2
Rolling back uninstall of pip
Moving to /Users/mm/Library/Python/3.9/bin/pip
from /private/var/folders/v_/3yqdc_t15jjb82bnmh1366ym0000gn/T/pip-uninstall-7x3mha7f/pip
Moving to /Users/mm/Library/Python/3.9/bin/pip3
from /private/var/folders/v_/3yqdc_t15jjb82bnmh1366ym0000gn/T/pip-uninstall-7x3mha7f/pip3
Moving to /Users/mm/Library/Python/3.9/bin/pip3.9
from /private/var/folders/v_/3yqdc_t15jjb82bnmh1366ym0000gn/T/pip-uninstall-7x3mha7f/pip3.9
Moving to /Users/mm/Library/Python/3.9/lib/python/site-packages/pip-22.2.dist-info/
from /Users/mm/Library/Python/3.9/lib/python/site-packages/~ip-22.2.dist-info
Moving to /Users/mm/Library/Python/3.9/lib/python/site-packages/pip/
from /Users/mm/Library/Python/3.9/lib/python/site-packages/~ip
ERROR: Exception:
Traceback (most recent call last):
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
return func(self, options, args)
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/commands/install.py", line 461, in run
installed = install_given_reqs(
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/req/__init__.py", line 73, in install_given_reqs
requirement.install(
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/req/req_install.py", line 752, in install
scheme = get_scheme(
File "/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/locations/__init__.py", line 244, in get_scheme
from . import _distutils
ImportError: cannot import name '_distutils' from 'pip._internal.locations' (/Users/mm/Library/Python/3.9/lib/python/site-packages/pip/_internal/locations/__init__.py)
Code of Conduct
- I agree to follow the PSF Code of Conduct.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Upgrade pip to 22.2.1 but receive error "cannot import name ...
I had this when my site-packages version of pip in Python39\lib\site-packages\pip had been upgraded by another tool (chocolatey) and was ...
Read more >Changelog - pip documentation v22.3.1
Upgrading a distutils installed item that is installed outside of a virtual environment, while inside of a virtual environment will no longer warn...
Read more >cannot import name '_distutils' from 'pip._internal.locations'
Upgrade pip to 22.2.1 but receive error "cannot import name '_distutils' ... to upgrade from 22.2 to 22.2.1, the install fails because of...
Read more >How can I upgrade pip to the latest version? - Ask Ubuntu
I have trouble with the last line. I get the error ImportError: No module named 'setuptools' , but when I run pip install...
Read more >pip 1.0 - PyPI
You can use pip install --upgrade SomePackage to upgrade to a newer version, ... Known exceptions include pure-distutils packages installed with python ...
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
Reinstalling from source works because the metadata preparation steps imports
_distutils
before the uninstall step, so it is in memory when reinstalling.So a workaround for people affected by this is to reinstall pip from source:
python -m pip install --user --upgrade https://github.com/pypa/pip/archive/refs/tags/22.2.1.zip
A reinstall fixed it for me.