DEV Community

Cover image for Setting up Python on macOS
Chris Bongers
Chris Bongers

Posted on • Originally published at

Setting up Python on macOS

I finally found myself in need of 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.

To demonstrate that, open a terminal and run the python command.
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

By far, 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
Enter fullscreen mode Exit fullscreen mode

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

Mac Python 3 installed

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

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
Enter fullscreen mode Exit fullscreen mode
alias python="python3"
Enter fullscreen mode Exit fullscreen mode

Now, 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!

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

Top comments (1)

waylonwalker profile image
Waylon Walker

Excited to see you start your venturing into python. Please do share us your work with open cv! It's not something I have used before, maybe after I see it in practice I'll wonder why I haven't used it before.