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 Sur which 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 andpyenv 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:

Install some prerequisites
brew install zlib sqlite bzip2 libiconv libzip

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

Install pyenv
brew install pyenv

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

Upgrade pyenv
brew 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:

Install Python 3.9.1 using pyenv
pyenv install 3.9.1
pyenv global 3.9.1
pyenv version

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

Info

Update: 11/06/2021; the command below has been updated to include a change to how the “pyenv init” command works.

Make sure the pyenv version is used
echo -e $'if command -v pyenv 1>/dev/null 2>&1; then\\n  export PYENV_ROOT="$HOME/.pyenv"\\n  export PATH="$PYENV_ROOT/bin:$PATH"\\n  eval "$(pyenv init --path)"\\n  eval "$(pyenv init -)"\\nfi' >> ~/.zshrc

Open a new shell and run:

Check the python version
python --version
which python

This should return something like the following:

Output of the commands
$ python --version
Python 3.9.1
$ which python
/Users/russ.mckendrick/.pyenv/shims/python

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

Update pip
pip install --upgrade pip

This fixed a few issues I had when I ran:

Install Ansible
pip install --user ansible

Which meant that I didn’t need to use my custom container anymore.