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 :
brew install pyenv
Once installed, I ran the following to download and compile Python 3.10.0:
pyenv install 3.10.0
pyenv global 3.10.0
pyenv version
The last command should return something similar to the following output:
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.
Info
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.
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:
python --version
which python
The final step is to make sure that pip
is up-to-date, to do this run:
pip install --upgrade pip
pip install --user ansible
ansible --version
As you can see from the output below, Ansible was isntalled and using the correct version of Python:
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 👍