How to Install Python on Mac?

I'll share a few ways to install Python on a Mac. Not everyone is satisfied with installing from the official site.

How to Install Python on Mac?
Photo by Chris Ried / Unsplash

The most common way to install Python on Mac is to visit the official Python website and download the latest version.

That might not be the best solution for some developers. So, aside from that solution, let's explore a few more.

Let me know which one of these suits you best in the comments below!

1. Download From The Official Python Website

The most straightforward way to install Python is to visit the official website and download the latest version from there.

Just visit Python's official website and click the download button.

The downloaded file is a macOS package that has its own installation. Double-clicking on it will guide you through the rest of the process.

Another Mac-specific way to download Python is to use Homebrew. Let's go over it now.

2. Download Python Using Brew

Homebrew is a package manager for Mac. Brew could touch many sensitive parts of your OS. If you're unsure how to use it, consider skipping this method. Or use it only as described below.

Refer to the official Homebrew documentation regarding Python here.

The Python version installed through Brew is usually singular, which means every time Brew performs updates, that version could be updated automatically.

To install Brew, run this command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After that command finishes, run this command next (replacing 3.13 with your desired version):

brew install python@3.13
⚠️
Remember! Installing version 3.13 will not lock the version to 3.13.0, minor versions like 3.13.3 could be installed as your system updates.

But what if you need a specific version that stays consistent? That's where PyEnv comes into play.

3. Install Specific Python Versions Using PyEnv

PyEnv allows you to install specific versions that do not interfere with one another. This is the best case scenario for someone who might need to work on multiple Python projects and have different dependencies for each project.

Imagine this: You have a service that uses Python 3.12 and you need to fix a bug in it. Next, you have another bug in a different service, and that one is using python 3.10.2.

Will you replace the one version on your computer every time you switch projects? Of course not! You would use a tool like PyEnv to install both so you can debug them separately.

To install PyEnv, use Homebrew:

brew install pyenv

Then you can install different python version by running the pyenv install command

pyenv install 3.10.2
pyenv install 3.12.0
pyenv install 3.13.3

PyEnv goes one step further and allows you to define what's the python version you want to use globally or locally. so if your project is using 3.10.2, you'd want to do this in the root folder of that project after installing 3.10.2 using PyEnv:

pyenv local 3.10.2

Now when you run the terminal and start Python, the default version to run when you're in this folder is 3.10.2 even if you have many other python versions installed.

To change the global python version, use the same command only replacing the word local with global. This will change the python version used when you type in python from any folder on your Mac:

pyenv global 3.10.2

This is easy, right? Saves you a lot of time. But what if you don't want to install so many Python versions on your machine? That's when you explore the option of never installing it and using Docker instead.

Bonus: Don't Download Python At All

One way to use whatever version of Python you need is to use Docker. Just install Docker Desktop and run your code in a dev container.

This can be a whole other post on its own, but if you want me to write it, please let me know in the comments below!

Have Any Questions?

Thanks for reading! If you have any questions, please let me know in the comments below. I'll do my best to answer all of them.