Managing Python on macOS Monterey
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:
``` terminfobrew install pyenv
Once installed, I ran the following to download and compile Python 3.10.0:
```bash frame="terminal" title="Install Python 3.10.0 using pyenv"``` terminfopyenv install 3.10.0pyenv global 3.10.0pyenv version
The last command should return something similar to the following output:
```bash frame="terminal" title="Output of the command"$ pyenv version3.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.
``` terminfoecho -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:
```bash frame="terminal" title="Check the python version"``` terminfopython --versionwhich python
```bash frame="terminal" title="Output of the command"$ python --versionPython 3.10.0$ 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:
``` terminfopip install --upgrade pip
```bash frame="terminal" title="Install Ansible"``` terminfopip install --user ansibleansible --version
As you can see from the output below, Ansible was isntalled and using the correct version of Python:
```bash frame="terminal" title="Output of the command"$ ansible --versionansible [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 👍
Related Posts

Installing and running InvokeAI on macOS
A step-by-step guide on installing and running InvokeAI on macOS for local AI image generation using Conda and Python.

Conda for Python environment management on macOS
Learn how to efficiently manage Python environments on your MacBook Pro using Conda. This comprehensive guide covers installation, creating and activating environments, installing packages, and best practices for streamlining your Python development workflow.

Upgrade Python on MacOS
Upgrade to Python 3 on macOS using pyenv for easy installation and maintenance of different Python versions.