When I use pip to download something, for example
pip install numpy
At this time, it will always show a notice reminding me that pip can be updated
[notice] A new release of pip available: 22.2.1 -> 22.3.1
[notice] To update, run: C:\Users\MyName\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe -m pip install --upgrade pip
When I entered the command it asked me to enter, the command prompt collecting pip, which then displayed a long list of information and exceptions
Requirement already satisfied: pip in c:\users\MyName\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (22.2.1)
Collecting pip
Using cached pip-23.0-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.2.1
Uninstalling pip-22.2.1:
Successfully uninstalled pip-22.2.1
Rolling back uninstall of pip
Moving to c:\users\MyName\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\scripts\pip.exe
from C:\Users\MyName\AppData\Local\Temp\pip-uninstall-yaigaesv\pip.exe
Moving to c:\users\MyName\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\scripts\pip3.9.exe
from C:\Users\MyName\AppData\Local\Temp\pip-uninstall-yaigaesv\pip3.9.exe
Moving to c:\users\MyName\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\scripts\pip3.exe
from C:\Users\MyName\AppData\Local\Temp\pip-uninstall-yaigaesv\pip3.exe
Moving to c:\users\MyName\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages\pip-22.2.1.dist-info\
from C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\~ip-22.2.1.dist-info
Moving to c:\users\MyName\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages\pip\
from C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\~ip
ERROR: Exception:
Traceback (most recent call last):
File "C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip\_internal\cli\base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip\_internal\cli\req_command.py", line 247, in wrapper
return func(self, options, args)
File "C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip\_internal\commands\install.py", line 461, in run
installed = install_given_reqs(
File "C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip\_internal\req\__init__.py", line 73, in install_given_reqs
requirement.install(
File "C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip\_internal\req\req_install.py", line 752, in install
scheme = get_scheme(
File "C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip\_internal\locations\__init__.py", line 244, in get_scheme
from . import _distutils
ImportError: cannot import name '_distutils' from 'pip._internal.locations' (C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip\_internal\locations\__init__.py)
I checked with a search engine and most of the solutions suggested that I should enter the following command to force a pip reinstallation.
python -m pip install -U --force-reinstall pip
But when I entered it, I found the same error message appeared. And based on ImportError, I found the first few lines on it by looking up the init code.I don't know if it's useful.
def get_scheme(
dist_name: str,
user: bool = False,
home: Optional[str] = None,
root: Optional[str] = None,
isolated: bool = False,
prefix: Optional[str] = None,
) -> Scheme:
new = _sysconfig.get_scheme(
dist_name,
user=user,
home=home,
root=root,
isolated=isolated,
prefix=prefix,
)
if _USE_SYSCONFIG:
return new
from . import _distutils
In addition to the above methods, I don't think the other methods online are very reliable, such as going into the pip init code to change things. What is the cause of this? I would like to know if I need to reinstall python, is there any downside if I keep the current pip version? Incidentally, for simple privacy, I changed all my usernames to "MyName", and my python version is 3.9. I have never encountered this kind of problem, and I don't know much about it. I would really appreciate it if you could help me solve it!
It seems you may be missing some utilities that come with pip, one thing you can try is to uninstall pip then reinstall using get-pip.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
If this does not work, try to reinstall python