This week was not only the release of macOS Monterey, but it was also new Mac Book Pro week for a lot of people, including myself. Given that it was alot of effot to install Python on macOS Big Sur I was a little worried that it would take the same amount of effort.

As I was starting a with a clean macOS Monterey installation and had already installed Homebew I just needed to run the following command to install pyenv :

Install pyenv
brew install pyenv

Once installed, I ran the following to download and compile Python 3.10.0:

Install Python 3.10.0 using pyenv
pyenv install 3.10.0
pyenv global 3.10.0
pyenv version

The last command should return something similar to the following output:

Output of the command
$ pyenv version
3.10.0 (set by /Users/russ.mckendrick/.pyenv/version)

Now that Python is installed and we have set version 3.10.0 to the default Python install used by pyenv, we need to run the following command to ensure that our preferred version is used whenever we open a new terminal session.


Please note: The command below assumes that you are using ZSH , if you are using a different shell please check the file path to your RC file is correct.

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

Output of the command
$ python --version
Python 3.10.0
$ which python

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

Update pip
pip install --upgrade pip

Install Ansible
pip install --user ansible
ansible --version

As you can see from the output below, Ansible was isntalled and using the correct version of Python:

Output of the command
$ ansible --version
ansible [core 2.11.6]
  config file = None
  configured module search path = ['/Users/russ.mckendrick/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/russ.mckendrick/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/russ.mckendrick/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/russ.mckendrick/.local/bin/ansible
  python version = 3.10.0 (default, Oct 26 2021, 20:43:52) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 3.0.2
  libyaml = True

This was a massive improvement on last years experience as it was far from smooth on day one, so props to pyenv and Homebrew teams ๐Ÿ‘