Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Homebrew Python and linking

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)

like image 601
Marsstar Avatar asked Jul 18 '17 15:07

Marsstar


People also ask

Should you install Python with homebrew?

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.

Can I have Python 2 and 3 installed at the same time Mac?

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".


1 Answers

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.

like image 84
nofinator Avatar answered Nov 13 '22 07:11

nofinator