I need to use the Homebrew version of Python rather than the system version of Python. I have a clean install of macOS Sierra (10.12.5).
I first installed homebrew and then updated ~/.bash_profile
using nano ~/.bash_profile
.
Then I added this into the file:
# Homebrew
export PATH=/usr/local/bin:$PATH
Then, I needed to manually source the ~/.bash_profile
file to ensure the changes have been reloaded using source ~/.bash_profile
.
I installed python using brew install python
and tried to link using brew linkapps python
The output was this:
Warning: Already linked: /usr/local/Cellar/python/2.7.13_1
To relink: brew unlink python && brew link python
Gautams-Air:~ gautam$ which python
/usr/bin/python
Gautams-Air:~ gautam$ python -V
Python 2.7.10
Gautams-Air:~ gautam$ brew linkapps python
Warning: brew linkapps has been deprecated and will eventually be removed!
Unfortunately brew linkapps cannot behave nicely with e.g. Spotlight using
either aliases or symlinks and Homebrew formulae do not build "proper" .app
bundles that can be relocated. Instead, please consider using brew cask and
migrate formulae using .app's to casks.
Linking: /usr/local/opt/python/IDLE.app
Linking: /usr/local/opt/python/Python Launcher.app
Linked 2 apps to /Applications`
Using which python
the output was:
/usr/bin/python
It should have been: /usr/local/bin/python
I also tried using: brew unlink python && brew link python
Also using python -V
it shows Python 2.7.10
although the current version in Homebrew is Python 2.7.13
How do I use the Homebrew version of Python instead of the system version of Python? - How do I do the linking?
USING: macOS Sierra (10.12.5)
Don't use Homebrew Python. It's not meant for you. At some point Homebrew made changes that adversely affect Python development. While Homebrew's Python formula has been the go-to choice for Python developers (including me) for a long time, that time is past — there are now much better options available.
Yep, you can install another python 2.7 through pyenv. It will install that python in $PYENV_ROOT/versions. The other python 2.7 installed through homebrew may appear as "system" when you execute "pyenv versions".
Due to a recent change in the Homebrew formula for python2 starting with version 2.7.13_1
, Homebrew no longer creates a symlink for python
to the Homebrew version.
Instead, it only installs and symlinks python2
. You will need to take an additional step to use it instead of the system version of Python.
See the "Caveats" section in this package's info. Below is an example, but note that the actual PATH to export is generated and may be different on your machine.
$ brew info python2
... snip ...
=> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
export PATH="<... some path ...>:$PATH"
... snip ...
Edit: Homebrew talked more about this change in their recent release notes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With