Managing Python on macOS Big Sur
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 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:
``` terminfobrew 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`:
```bash frame="terminal" title="Install pyenv"``` terminfobrew install pyenv
If like me, you need to upgrade, then you can run:
```bash frame="terminal" title="Upgrade pyenv"``` terminfobrew 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:
```bash frame="terminal" title="Install Python 3.9.1 using pyenv"``` terminfopyenv install 3.9.1pyenv global 3.9.1pyenv version
Once installed, run the following command to make sure that the `pyenv` managed version of Python is picked up:
<InfoCallout title="Info">**Update: 11/06/2021;** the command below has been updated to include a change to how the "pyenv init" command works.</InfoCallout>
```bash frame="terminal" title="Make sure the pyenv version is used"``` 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
This should return something like the following:
```bash frame="terminal" title="Output of the commands"$ python --versionPython 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:
``` terminfopip install --upgrade pip
This fixed a few issues I had when I ran:
```bash frame="terminal" title="Install Ansible"``` terminfopip install --user ansible
Which meant that I didn't need to use [my custom container anymore](/2020/12/28/ansible-azure-and-macos-big-sur/).
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.

Managing Python on macOS Monterey
Just installed macOS Monterey and Python on my MacBook Pro! Easy peasy with pyenv. Check out my experience!