I'm running macOS 11.2.2 Big Sur and I'm trying to get pip to work with the latest Python 3.9.4. This turned out to be ridiculously difficult even though I've read a number of articles on the subject. Possibly, it is the debris I accumulated in the system over the years which is causing me trouble. I need advice as to how to get things right again.
Checklist:
/usr/local/opt/python/bin/python3 --version
is Python 3.9.4 installed from brew
in the most usual way; it's a symlink to ../Frameworks/Python.framework/Versions/3.9/bin/python3
, which is in Cellar
.
Both python
and python3
commands are aliased to /usr/local/opt/python/bin/python3
, they give the correct version.
I used both get-pip.py and ensurepip , and both of them say everything is fine: "Successfully installed pip-21.1.1 setuptools-56.0.0"
The only thing in env
that has anything to do with Python is this part of PATH: /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/bin
. The lack of this one is reported as warning when you install pip.
Still, I get this:
python -m pip --version
/usr/local/opt/python@3.9/bin/python3.9: No module named pip
What am I missing?
I also found this article that instructs to use pyenv
, but running it on the latest macOS is yet another problem: pyenv install 3.9.4
doesn't build for some reason.
Using pointers from @gold_cy
in the comments I was able to resolve the problem by running get-pip.py
with an additional parameter: --prefix=/usr/local/
.
While the official pip installation guide does mention that there may be problems on the systems like macOS that manage their own Python install, it doesn't say directly what you can do about it. Which is a shame, because the phrasing in PyPA » Python Packaging User Guide » Tutorials » Installing Packages is exactly the same, only the last phrase is missing from pip's page:
Warning Be cautious if you're using a Python install that's managed by your operating system or another package manager.
get-pip.py
does not coordinate with those tools, and may leave your system in an inconsistent state. You can use pythonget-pip.py --prefix=/usr/local/
to install in/usr/local
which is designed for locally-installed software.
I was trying to resolve the problem for python3
in MacOS. The accepted answer didn't help me.
What helped me is complete reinstall of the python3:
brew uninstall python3 # if python3 worked before
brew install python3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.