Subscribe

Setting up Python on macOS

✍️

A basic setup for Python on the macOS system

16 May, 2021 Β· 2 min read

I finally found myself needing some Python to do some OpenCV work on my Mac. And although Mac nowadays comes with Python pre-installed, it's not the exact version we are looking for.

Open a terminal and run the python command to demonstrate that. This should now return version 2.

Mac default Python installation

So how can we make sure that we have the latest Python version available on our Mac system?

Mac installing Python 3 permalink

The easiest way to install Python 3 is to use Homebrew. If you haven't had Homebrew installed yet, check out this article explaining how to set up Homebrew on your Mac.

With Homebrew installed, we can install Python, and it will install the latest stable (at the time of writing 3.9).

brew install python

And once that is done, we should run the python3 command to see if our version matches.

Mac Python 3 installed

However, it's a bit of a mission to manually type the number three after Python.

To fix that, we can add a new alias to link python3 to the command python.

I'm using Zsh, so I have a ~/.zshrc file, open this file and add the following line.

nano ~/.zshrc
alias python="python3"

If you restart your terminal, you should run just the python command.

Python default command version 3

And that's it. We now have the latest version of Python installed on our MacOs system.

Thank you for reading, and let's connect! permalink

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Spread the knowledge with fellow developers on Twitter
Tweet this tip
Powered by Webmentions - Learn more

Read next πŸ“–

Speedtest your connection in Python

21 Jun, 2021 Β· 3 min read

Speedtest your connection in Python

F-strings in Python

7 Jun, 2021 Β· 2 min read

F-strings in Python

Join 1365 devs and subscribe to my newsletter