Install Pyenv:
brew install pyenv
Configure Pyenv in your shell:
# Add this to your ~/.zshrc or ~/.bash_profile
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv > /dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init ~)"
source ~/.zshrc
OR
source ~/.bash_profile
Use pyenv:
# List available Python versions
pyenv install --list
# Install a specific version
pyenv install 3.11.5
pyenv install 3.12.0
# List installed versions
pyenv versions
# Set global Python version
pyenv global 3.11.5
# Set local Python version for current directory
pyenv local 3.12.0
# Check current version
python --version