How to install Python on MacOS

By | February 5, 2025

Installing pyenv (brew install pyenv)

The first step is to install pyenv which is Python’s version management system. You can read more about where it came from and what it does here but in a nutshell, it is a project that was forked from rbenv and ruby-build, and modified for Python and it let’s you change your python version on a global level and also on a project level. ie, it is a highly recommended must have.

To install it, run:

brew update
brew install pyenv

Some other useful (and self explanatory) commands:

brew reinstall pyenv
pyenv --version 
where pyenv (should return /opt/homebrew/bin/pyenv)
pyenv (displays a list of useful commands)

You will have to set up your shell environment and also some python build dependencies outlined here.

Installing Python

Do you have Python already? (python3 –version)

Instead of running pyenv install 3.10.4 or whatever version you are interested in, first run python3 –version to see if you have Python already installed. For me on Sonoma, it showed v3.9.6

Note on Anaconda

However, I had Anaconda installed which modified my PATH file and messed things up a bit. When it was in my PATH, (Anaconda injected it at the very start of the PATH meaning it overrode everything else), Python returned version 3.12.7.

To remove Anaconda from the PATH, just remove it from .zshrc (or .bash if that is what you are using). Also, don’t forget to restart terminal as well. Either close and reopen or run source ~/.zshrc

Listing Python versions (pyenv install -l)

Once you know if you have Python or not and if yes, what version, you still don’t want to install Python yet! Run pyenv install -l to list all the available Python versions available to install. Warning: You’ll get a lot!

At the time of this writing, you’ll probably want to install v3.13 something. But here is where you should see the power of pyenv. If you had some code that needed v3.7 for example, you could install that as well. You can install as many versions as you want.

Installing Python (pyenv install 3.13.0)

Now comes the time to install Python. Simple run pyenv install 3.13.0 for instance.

Checking installed versions (pyenv versions)

Then run pyenv versions to list all the different versions installed. The * means the current active version. Note versions is plural. The singular word returns the currently active Python version for your shell session.

Switching to another version (pyenv shell 3.x.x)

To switch to another version, use the command pyenv shell + the version number. Then run pyenv version again or versions and you should see the asterix next to the new version.

Leave a Reply

Your email address will not be published. Required fields are marked *