pyenv is a tool for managing multiple Python environments. It allows you to easily install and switch between different Python versions.
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# Install with brew
brew install pyenv
# Auto installer
curl https://pyenv.run | bash
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
# show installed versions:
pyenv versions
# list the available versions of python3
pyenv install --list | grep " 3\.[6789]"
# Install a specific python version
pyenv install 3.9
pyenv global 3.9
pyenv local 3.9
pyenv shell 3.9
pyenv local --unset
pyenv shell --unset
pyenv virtualenv 3.9 project_environment
# Activating the virtual environment
pyenv activate project_environment
# Deactivating the virtual environment
pyenv deactivate