How To Use Python Version Management with Pyenv

Install Pyenv

Install Pyenv using package managers like Homebrew on macOS or Git for other systems. Follow platform-specific instructions to set it up.

Update Environment

Add Pyenv to your shell by updating .bashrc, .zshrc, or equivalent. This ensures Pyenv works every time you open a terminal.

Install Python Versions

Use pyenv install <version> to install specific Python versions. Check available versions with pyenv install --list.

Set Python Versions

Use pyenv global <version> to set a global default or pyenv local <version> for project-specific settings.

Switch Versions

Switch between Python versions quickly using pyenv shell <version>. It overrides global and local settings for the session.

Troubleshooting

Ensure dependencies like build-essential are installed on Linux. Run pyenv doctor to diagnose and fix issues.