Installing Python on Mac OS X

Installing Python on Mac OS X other than the default one that is shipped with your system.

  • System Check
$ which python

$ python –V
Python 2.7.10

$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
  • Installing Homebrew
$ /usr/bin/ruby –e "$(curl -fsSL"

Edit your .bash_profile adding /usr/local/bin to your PATH session environment variable, so that /usr/local/bin will take precedence over.

$ vim ~/.bash_profile

Add this to the file:

export PATH=/usr/local/bin:$PATH

Make changes effective for your current session.

$ source ~/.bash_profile
$ echo $PATH
  • Installing Python with Homebrew

Python 2.7.

$ cd /usr/local
$ brew update
$ brew doctor
$ brew install python

Python 3 (Optional but recommended).

$ brew install python3

And finally check again where Python is located and version.

$ which python

$ python -V
Python 2.7.12

$ python
Python 2.7.12 (default, Nov  8 2016, 17:33:27) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.


Always make sure Homebrew is updated and healthy before installing anything.

$ brew update
$ brew doctor