ImportError: cannot import name 'PackageFinder'
Solution 1
It seems that this works. Reinstall the latest version of pip:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py
When you’re done, delete the installation script:
$ rm get-pip.py
Solution 2
Solved this by manually updating: Command Line Tools for XCode.
From the terminal run:
softwareupdate --list
which produces a list of available updates.
Wait a bit for a list to display (won't take very long). And look for the "* Label:" under Software Update found the following new or updated software:
It should say something like: * Label: Command Line Tools for Xcode-13.0
Then simply run: softwareupdate -i "Command Line Tools for Xcode-13.0"
and replace the text in the brackets with the Label from the previous output. This will then install the updates and the fix for python3.
Then run: pip3 --version
and it should work.
Solution 3
This happens usually, if you try to reinstall pip and the distro's pre-packaged version mismatches the previously installed version (e.g. 19.0.3 (packaged)
vs 20.0.2 (installed)
at time of writing).
Removing the /path/to/site-packages/pip*
directories is a simple (yet safe) solution.
Here's a little bash script for the system installed version (thus requires sudo):
#!/bin/bash
set -e
# Set PY_MAJ and PY_MIN with your own python "major.minor" version
# Example for python 3.8
# PY_MAJ='3'
# PY_MIN='8'
cd /usr/lib/python${PY_MAJ}.${PY_MIN}/site-packages/ \
&& rm -rf pip/ \
&& rm -rf pip-*/ \
; cd -
Note for virtual environments: Basically the same is valid for venv's. Only difference is the "site-packages" directory location.
Solution 4
I had a similar error installing python3 (3.6.9) and pip3 on Alpine 3.7.
In my case the answer was follow the python install/upgrade with:
python3 -m ensurepip --upgrade
The --upgrade option will cause it to uninstall any old versions and install a version compatible with the python version
Hassan Daoud
Updated on October 23, 2021Comments
-
Hassan Daoud over 2 years
after updating everything in conda, pip can't install anything
conda update -n base conda conda update --all
when install or upgrade anything, this error is show
$ pip install --upgrade HDF5 Traceback (most recent call last): File "C:\ProgramData\Anaconda3\Scripts\pip-script.py", line 10, in <module> sys.exit(main()) File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_internal\main.py", line 45, in main command = create_command(cmd_name, isolated=("--isolated" in cmd_args)) File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_internal\commands\__init__.py", line 96, in create_command module = importlib.import_module(module_path) File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_internal\commands\install.py", line 23, in <module> from pip._internal.cli.req_command import RequirementCommand File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_internal\cli\req_command.py", line 17, in <module> from pip._internal.index import PackageFinder ImportError: cannot import name 'PackageFinder'
any help please. thank you.
-
akya about 4 yearsThank you so much. This helped me with the trouble I got in after using sudo with pip :D
-
Samuel Waller almost 2 yearsrunning this, it got stuck at installing and won't let me stop it.
-
Gerry almost 2 yearsCan you share the error message? Have you tried restarting your mac and then trying again?
-
Samuel Waller almost 2 yearsThere was no error message, it just took forever and there is no way to stop it short of killing the process, which seems like a bad idea. It ended up taking 5 hours to update everything with my slow internet
-
Gerry almost 2 yearsOk, glad it worked for you.