15 Feb 2026

pyenv

A quick guide to using pyenv for managing multiple Python versions on macOS, with industry best practices for development.

python pyenv macos development industry

Pyenv is an essential tool for Python developers, especially when working on multiple projects that require different Python versions. It allows you to easily switch between versions and maintain project-specific environments without affecting your system Python. Some key benefits of using pyenv include:

Frequently Used Commands

  • pyenv install -l List all available Python versions for installation
  • pyenv install <version> Install a specific Python version
  • pyenv global <version> Set the global default Python version
  • pyenv local <version> Set a Python version for the current project
  • pyenv shell <version> Temporarily switch Python version for the current shell session
  • pyenv --version Display the currently active Python version
  • pyenv which python Show the path to the currently active Python executable
  • pyenv uninstall <version> Uninstall a specific Python version
  • pyenv rehash Rebuild the shims after installing/uninstalling versions

Why Use `pyenv local` Inside Each Project?

When you have multiple projects, each may require a different Python version. Using pyenv local allows you to set a specific Python version for each project without affecting others.

pyenv local 3.11.7

What it does:

Effect:

Why Combine With Virtual Environment (venv)?

Even if two projects use the same Python version,
their installed packages may differ.

Example:

To avoid package conflicts:

python -m venv venv  
source venv/bin/activate  

Explanation:

python -m venv venv Creates a private isolated environment folder named venv.

source venv/bin/activate Activates that isolated environment.

After activation:

Combined Industry Command Explained

pyenv install 3.11.7 && pyenv local 3.11.7 && python -m venv venv

Step-by-step:

  1. Installs Python 3.11.7
  2. Sets that version only for the current project
  3. Creates an isolated virtual environment

This gives:

Standard Project Structure

my-project/
|– .python-version
|– venv/
|– app.py
|– requirements.txt

Every project has:

Share This Page