Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade pip to 22.2.1 but receive error "cannot import name '_distutils' from 'pip._internal.locations"

Tags:

python

pip

I tried to upgrade pip by the command "python -m pip install --user --upgrade pip" however it is not successful. I receive the below error message

ImportError: cannot import name '_distutils' from 'pip._internal.locations' 
ImportError: cannot import name '_distutils' from 'pip._internal.locations'      
[notice] A new release of pip available: 22.2 -> 22.2.1
[notice] To update, run: python.exe -m pip install --upgrade pip

Please advise how to resolve this

like image 912
pplhung Avatar asked Oct 30 '25 19:10

pplhung


1 Answers

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 ahead of my user-base version in appdata\roaming\python\python39\scripts. To clear this error I uninstalled the user-base version of pip and setuptools:

c:\Python39\python -m pip uninstall pip setuptools
Found existing installation: pip 22.2
Uninstalling pip-22.2:
  Would remove:
    c:\users\anotherdave\appdata\roaming\python\python39\scripts\pip.exe
    c:\users\anotherdave\appdata\roaming\python\python39\scripts\pip3.9.exe
    c:\users\anotherdave\appdata\roaming\python\python39\scripts\pip3.exe
    c:\users\anotherdave\appdata\roaming\python\python39\site-packages\pip-22.2.dist-info\*
    c:\users\anotherdave\appdata\roaming\python\python39\site-packages\pip\*
Proceed (Y/n)? y
  Successfully uninstalled pip-22.2
Found existing installation: setuptools 63.4.2
Uninstalling setuptools-63.4.2:
  Would remove:
    c:\users\anotherdave\appdata\roaming\python\python39\site-packages\_distutils_hack\*
    c:\users\anotherdave\appdata\roaming\python\python39\site-packages\distutils-precedence.pth
    c:\users\anotherdave\appdata\roaming\python\python39\site-packages\pkg_resources\*
    c:\users\anotherdave\appdata\roaming\python\python39\site-packages\setuptools-63.4.2.dist-info\*
    c:\users\anotherdave\appdata\roaming\python\python39\site-packages\setuptools\*
Proceed (Y/n)? y
  Successfully uninstalled setuptools-63.4.2

Then checking for an update of the site-packages pip confirmed it was up to date:

c:\Python39\python -m pip install --upgrade pip
Requirement already satisfied: pip in c:\python39\lib\site-packages (22.2.2)
like image 94
anotherdave Avatar answered Nov 01 '25 09:11

anotherdave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!