Simple Guide to Installing and Switching Python Versions with pyenv

Advertisement

Apr 23, 2025 By Tessa Rodriguez

Managing different Python versions on your computer doesn’t have to be complicated. That's where pyenv steps in. If you ever felt stuck juggling projects that need different Python versions, you’re going to love how simple pyenv makes it. It lets you easily switch between versions without creating any mess on your system. Whether you’re working on an old Django project or the latest data science experiment, pyenv keeps everything clean and organized.

What is pyenv and Why Should You Care?

Most systems already come with a version of Python installed. The problem? It's often outdated. Plus, different projects require different versions. If you manually install and switch Python versions, you can quickly end up with conflicts, broken environments, and a lot of unnecessary frustration.

Pyenv fixes all that by letting you install and manage multiple versions of Python side-by-side. You get to pick the exact version you want for each project. Even better, it won’t interfere with your system’s default Python. Think of it like having a magic remote control that lets you change your Python version anytime you want — without needing to reboot your system or fix broken packages afterward.

The best part? pyenv is lightweight, easy to use once you get the hang of it, and it saves you from a lot of unnecessary headaches down the road.

It’s especially useful if you’re someone who likes working on multiple projects at once, where each one has its own specific requirements. Instead of adjusting everything manually or running into system-wide issues, pyenv keeps things clean, separated, and stress-free.

Installing pyenv the Right Way

Before jumping into installation, make sure you have a few basic tools ready. You’ll need curl, git, build-essential, and other dependencies that your operating system might ask for. These help pyenv compile and install different Python versions properly.

If you're on macOS, the simplest way to install pyenv is by using Homebrew:

bash

CopyEdit

brew update

brew install pyenv

On Ubuntu or Debian-based systems, you’ll want to run:

bash

CopyEdit

sudo apt update

sudo apt install -y make build-essential libssl-dev zlib1g-dev \

libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \

libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev

curl https://pyenv.run | bash

After installing, you’ll need to add pyenv to your shell’s startup file. This ensures that every time you open a new terminal, pyenv is available. Depending on your shell, it could be .bashrc, .bash_profile, .zshrc, or .profile. Add the following lines:

bash

CopyEdit

export PATH="$HOME/.pyenv/bin:$PATH"

eval "$(pyenv init --path)"

eval "$(pyenv init -)"

Reload your shell by closing and reopening your terminal, or run:

bash

CopyEdit

source ~/.bashrc

(or whichever file applies).

Once done, typing pyenv should show you a list of available commands. Congratulations, you’re all set up!

If you run into any trouble during setup, double-check that your shell configuration is correct and that you installed all the necessary dependencies. Most issues with pyenv usually come from missing packages or not updating the shell properly.

How to Install and Switch Between Python Versions

Now for the fun part. Installing a new version of Python is as easy as:

bash

CopyEdit

pyenv install 3.11.2

You can replace 3.11.2 with any version you need. To see a full list of installable versions:

bash

CopyEdit

pyenv install --list

Once your version is installed, you can set it globally (for your entire system) like this:

bash

CopyEdit

pyenv global 3.11.2

Or, if you want a specific version for just one project directory:

bash

CopyEdit

pyenv local 3.8.10

This creates a .python-version file in the project folder, telling pyenv to automatically use that version whenever you’re in that folder.

Switching between versions is automatic based on where you are in your system. If you move into a project folder that has a specified local version, Pyenv will switch to it without asking. Step outside, and it will go back to the global version. No manual commands needed, no fuss.

If you ever need to check which Python version pyenv is currently using:

bash

CopyEdit

pyenv version

Or, if you want to see all installed versions on your system:

bash

CopyEdit

pyenv versions

Everything stays neat, and you’re in full control.

One thing to keep in mind: when installing a new Python version with pyenv, it compiles from the source. So, it might take a little while, depending on your machine's speed. But it's usually a one-time thing per version, and after that, switching is instant.

Bonus Tips to Make pyenv Even Better

Once you’re comfortable using pyenv, a few small tweaks can make your experience even smoother.

First, there’s pyenv-virtualenv. This plugin lets you create and manage virtual environments directly through pyenv. You install it like this:

bash

CopyEdit

brew install pyenv-virtualenv

or

bash

CopyEdit

git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

Then, add these lines to your shell startup file (right after the pyenv init lines):

bash

CopyEdit

eval "$(pyenv virtualenv-init -)"

Now, you can create a virtual environment tied to a specific Python version:

bash

CopyEdit

pyenv virtualenv 3.11.2 myenv311

And activate it with:

bash

CopyEdit

pyenv activate myenv311

Or deactivate it:

bash

CopyEdit

pyenv deactivate

Using virtual environments makes your projects even more isolated. You avoid mixing up packages across different projects, and your global Python stays clean.

Another tip: if you’re managing multiple projects, setting a local virtual environment per project keeps everything even more self-contained. It keeps project-specific dependencies from leaking into other projects, which is especially useful if you’re working with different package versions.

And one last suggestion: Always keep your pyenv updated. If you installed it with Homebrew:

bash

CopyEdit

brew update

brew upgrade pyenv

Or if you installed it manually:

bash

CopyEdit

cd $(pyenv root)

git pull

Updating ensures you get the latest features, better stability, and support for new Python releases as soon as they come out.

Wrapping It Up!

Using pyenv is one of those small changes that makes a big difference. It takes away the hassle of managing Python versions, keeps your projects running smoothly, and saves you from the confusion of version conflicts. Once you set it up, switching between Python versions feels effortless. If you’re serious about keeping your development setup clean and easy to manage, pyenv is the tool you’ll be glad you started using.

Advertisement

Recommended Updates

Applications

How On-Device AI Works and Why It’s the Future of Everyday Tech

Alison Perry / May 08, 2025

Heard about on-device AI but not sure what it means? Learn how this quiet shift is making your tech faster, smarter, and more private—without needing the cloud

Technologies

Understanding the Power and Purpose of Small Language Models

Alison Perry / Apr 30, 2025

Can smaller AI models really compete with the giants? Discover how Small Language Models deliver speed, privacy, and lower costs—without the usual complexity

Technologies

Emotion Detection: 8 Datasets You Should Know About

Alison Perry / May 02, 2025

Need reliable datasets for emotion detection projects? These 8 options cover text, conversation, audio, and visuals to help you train models that actually get human feelings

Applications

NLP vs Machine Learning: How They Work, What They Do, and Why It Matters

Tessa Rodriguez / May 09, 2025

Not sure how Natural Language Processing and Machine Learning differ? Learn what each one does, how they work together, and why it matters when building or using AI tools.

Technologies

How Does Snowflake Fuel EdTech Vendor's Data and AI Initiatives

Tessa Rodriguez / Apr 28, 2025

Discover how Snowflake empowers EdTech vendors with real-time data, AI tools, and secure cloud solutions for smarter learning

Applications

Simple Guide to Installing and Switching Python Versions with pyenv

Tessa Rodriguez / Apr 23, 2025

Tired of dealing with messy Python versions across different projects? Learn how pyenv can help you easily install, manage, and switch between Python versions without the headaches

Technologies

How Claude 3 Haiku Is Revolutionizing AI Speed in 2025

Alison Perry / May 03, 2025

Looking for an AI that delivers fast results? Claude 3 Haiku is designed to provide high-speed, low-latency responses while handling long inputs and even visual data. Learn how it works

Applications

Mastering Video Creation with InVideo: A Simple Guide for Beginners

Tessa Rodriguez / May 03, 2025

Learn how to create professional videos with InVideo by following this easy step-by-step guide. From writing scripts to selecting footage and final edits, discover how InVideo can simplify your video production process

Applications

Using ChatGPT to Automate Document Writing in Microsoft Word

Tessa Rodriguez / Apr 29, 2025

Looking for a quicker way to create documents in Word? Learn how to use ChatGPT to automate your document writing process directly within Microsoft Word

Technologies

Create 3D Models from a Single Image Using TripoSR

Alison Perry / May 04, 2025

Wondering how to turn a single image into a 3D model? Discover how TripoSR simplifies 3D object creation with AI, turning 2D photos into interactive 3D meshes in seconds

Applications

Is Your Chatbot Secretly Exposing Sensitive Data? Let’s Find Out!

Tessa Rodriguez / May 08, 2025

Ever wondered if your chatbot is keeping secrets—or spilling them? Learn how model inversion attacks exploit AI models to reveal sensitive data, and what you can do to prevent it

Applications

Public, Private, and Personal AI: How They Differ and Why It Matters

Alison Perry / May 09, 2025

Not all AI works the same. Learn the difference between public, private, and personal AI—how they handle data, who controls them, and where each one fits into everyday life or work