简体   繁体   中英

How to change pip3 path after installing python with homebrew?

I previously installed Python 3 through the official distribution but recently decided to use Homebrew. I followed this to change my Python 3 path: Homebrew not linking python correctly?

This is how my python 3 path looks (which is what I want):

$which python
/usr/local/bin/python
$python --version
Python 3.7.5

However, now pip is using the official distribution but I want to change it to the Homebrew version

$which pip
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip

$pip --version
pip 19.3.1 from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip (python 3.6)

How do I change my pip path to the Homebrew version and remove the official distribution safely?

You need to remove /Library/Frameworks/Python.framework from your PATH . That was added when you installed Python from the official distribution). Or, at least not put it at the beginning, so that Homebrew's Python (the one in /usr/local/bin ) will be the one used by your system.

In your ~/.bash_profile , try this:

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

then restart your Terminal or source ~/.bash_profile . Homebrew's pip should be in /usr/local/bin , installed along with Homebrew's Python.

That should also have been the fix for the system not using Homebrew's Python.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM