ImportError: cannot import name 'PackageFinder'
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.
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.
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
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