macOS - Installing Python with Brew and pyenv

In this example, we will update Python 3.9.1 (Mac-supported) to Python 3.10.5 (Pyenv-supported)

macOS -  Installing Python with Brew and pyenv
Photo by Timothy Dykes / Unsplash
  1. Install pyenv
brew install pyenv

2. Use pyenv to install the Python version you want

pyenv install 3.10.5

2.1 Change Python version

pyenv versions
* system (set by /Users/devtooler/.pyenv/version)
  3.10.5
verify the current active version
pyenv global 3.10.5
pyenv versions
  system
* 3.10.5 (set by /Users/devtooler/.pyenv/version)
Change Python version and verify new version

3. Update zsh shell, you will still need to update zsh in order for pyenv to have an affect from the shell

python3 --version
Python 3.9.1
before updating zshrc 
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
python3 --version
Python 3.10.5
after updating zshrc

Extra

Hints: https://github.com/pyenv/pyenv/wiki#how-to-build-cpython-with-framework-support-on-os-x

If you use Pycharm you can add the following command to create the virtual enviornment for your project

pyenv virtualenv 3.10.5 projectName-3.10.5

Subscribe to Devtooler

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe