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.

upgrade from 22.2 to 22.2.1. fails with ImportError for name '_distutils'

See original GitHub issue

Description

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
sbidoulcommented, Jul 30, 2022

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

3reactions
fossumcommented, Jul 29, 2022

A reinstall fixed it for me.

python -m pip uninstall -y pip
python -m pip install --user --upgrade pip
Read more comments on GitHub >

github_iconTop 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 >

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