When Apple releases a new version of macOS it always takes a few months for everything to catchup, following my last blog post where I mentioned that I was having problems installing Python on macOS Big Surwhich meant that my preferred method of installing and managing Python using pyenv, which is documented in this blog post, didn't work out of the box — and the workarounds suggested workarounds on GitHub made my shell really slow.

Luckily, I noticed that there was an update to both Python and also pyenv when I ran brew update today so decided to give pyenv another try, and it worked as expected.

First I manually installed some prerequisites suggested on various GitHub issues, just to be on the safe side:

$ brew install zlib sqlite bzip2 libiconv libzip
Install the prerequisites

Next up you can either install or upgrade to the latest version of pyenv, which during writing is 1.2.22:

$ brew install pyenv
Install pyenv

If like me, you need to upgrade, then you can run:

$ brew upgrade pyenv
Upgrade pyenv

Once the latest version pyenv has been installed, run the following commands to install the latest stable version of Python, which is currently 3.9.1:

$ pyenv install 3.9.1
$ pyenv global 3.9.1
$ pyenv version
Install Python 3.9.1 and enable it globally

Once installed, run the following command to make sure that the pyenv managed version of Python is picked up:

$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\\n  eval "$(pyenv init -)"\\nfi' >> ~/.zshrc
Configure ZSH to use the pyenv managed version of Python

Open a new shell and run:

$ python --version
$ which python
Check the version of python in your shell

This should return something like the following:

Checking the version of Python and its part

The final step is to make sure that pip is up-to-date, to do this run:

$ pip install --upgrade pip
Upgrade pip

This fixed a few issues I had when I ran:

$ pip install --user ansible
Example of command I ran once Python was installed