This is part 1 in a five part series on getting started with Python on macOS.
The operating system on Mac computers (macOS) comes with a version of Python pre-installed. To see your currently installed version, in Terminal enter:
Note that you should not enter the actual $ sign. It is used as an indicator that this is entered at the UNIX/Bash prompt.
Wait for the install to finish. Then open Xcode to agree to the license.
If you have made a fresh install of XCode, you will also need to add the command line tools by running this in Terminal:
While macOS comes with a large number of UNIX utilities, those familiar with Linux systems will notice one key component missing: a package manager. Homebrew fills this void. Install it by entering this (as one single line) in Terminal:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Python 3
$ brew install python3
Launch the default system Python interpreter (as we did at the beginning):
Exit that Python and go back to bash:
The '>>>' here, indicates that we are at the Python (as opposed to the bash '$') prompt.
Launch the homebrew installed Python 3 interpreter (which is what we want to work with):
We are done with the installation! It is also recommendable to set python3 to be the default python, and also its package manager pip3 to be the default pip. To do this, in Terminal, open your bash profile for editing:
$ nano ~/.bash_profile
Type these two lines into the editor:
alias python='python3' alias pip='pip3'
Press control+X to close, Y to confirm, and Enter to save. Then refresh your bash profile:
$ source ~/.bash_profile
Now just entering python or pip in Terminal will always point to the right versions (3) on your computer.