Get started with Python on a Mac – Quick and easy and up to date for 2020

Get started with Python on a Mac – Quick and easy and up to date for 2020

Links on Code Thump may pay us an affiliate commission. Details here.

Python on a Mac – Quick start

Here’s how to get started with Python on a Mac.
MacBooks come with an old version of Python 2 pre-installed. You want to work with an up to date version of Python 3.

you can check what version of Python you have installed with this command:

  1. Open a terminal
  2. Type python --version

It will say something like Python 2.7.16

The best way to install Python is to use Homebrew.
Homebrew is a package manager which will take care of future updates and managing different versions.
I’m assuming that if you’re here then you probably don’t already have Homebrew so we’ll start from scratch.

There are just 3 steps:

  1. Install XCode command line tools
  2. Install Homebrew
  3. Install Python 3

XCode is the Apple development environment and includes tools you’ll need for a lot of development tasks on your Mac.
XCode and Homebrew are tools that you will use frequently when developing on a Mac.

1. Install XCode command line tools

Open a terminal and enter this command:

xcode-select --install

Give Apple the rights to your first-born by accepting the licence agreement, and proceed.
The installation may take a few minutes.
For info, the tools are installed to  /Library/Developer/CommandLineTools. It includes commands like gcc and git.

2. Install Homebrew

Copy and paste this command into a terminal window:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

There’ll be some prompts to answer. When it has finished installing, confirm it with this command:

brew doctor

3. Install Python 3

Open a terminal and enter this command:

brew install python3

When it finishes, confirm that Python 3 is now installed with this command:

python3 --version

4. Use Python 3

Now let’s use Python by running an interactive Python interpreter. In a terminal, enter this command:

python3

At the prompt, try entering 2+2 and hit return

Exit the Python interpreter by typing exit() and hitting return.

Did you know you can embed a Python interpreter in an HTML page and in a WordPress post? See this tutorial for simple instructions.

Scroll to Top