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)
- 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
pyenv global 3.10.5
pyenv versions
system
* 3.10.5 (set by /Users/devtooler/.pyenv/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
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
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