How to switch between Python Versions on MacOS using „pyenv“.

Why do you need to switch between Python Versions?

Well some projects use different versions of python either natively or in their dependencies. Thats where „pyenv“ comes in handy.
With pyenv you can manage python versions global or even locally in your project directory.

How do I install „pynev“?

The easiest way, at least for me, is using Homebrew. Just run the following command.

brew install pyenv

After installing pyenv via Homebrew you can check if the installation was succesfull by opening a new Terminal and run the following.

which pyenv

After that you should get a return like this:


If not you have to add some information to yours terminals PATH. Details are descript in the pyenv README.

How do I use „pyenv“ ?

Installing a python version

So how the fun do I use it then? Well first of all you can list the available python version with:
(You just need to run the update to get the latest python versions listed)

brew update && brew upgrade pyenv
pyenv install --list

The return in your terminal will look some what like this.


Pyenv will show you every possible versions of python and the branches.
What you are looking for, at least when you want the „normal“ python versions is this.
You maybe need to scroll up a bit.


Then you can install the latest stable version of python. In this case 3.11.1.

pyenv install 3.11.1

To check the if the python version was successfully installed, and which versions are also installed run the following.

pyenv versions

The return will look like this.

* system (set by /Users/max/.pyenv/version)

Congratulations the python version you wanted was successfully installed.
The star will tell you which version is currently used globally.

Switching python versions

You can select a local python version by running the following.

pyenv local 3.11.1

This will create a „.python-version“ file which tells pyenv what version to use.

To select a global python version with the following command.

pyenv global 3.11.1