Skip to content

Python Virtual Environments - Everything You Need

· 4 min

If you’ve ever Googled “how to install Python packages safely” or “why is my project breaking after a new pip install?”, you’ve likely stumbled into the confusing world of Python virtual environments.

Should you use venv? What about virtualenv? And what’s the deal with pyenv and conda — are they the same? 🤯

Don’t worry — you’re not alone. Even experienced developers sometimes mix them up.

In this guide, we’ll break it all down for you in plain English:

No jargon. No assumptions. Just clean, beginner-friendly explanations with real examples.


Table of Contents#

  1. What Is a Python Virtual Environment (and Why Should You Care?)
  2. The Big 4: virtualenv vs venv vs pyenv vs conda
  3. How to Use Them (with Examples)
  1. Which One Should You Use?

1. What Is a Python Virtual Environment (and Why Should You Care)?#

The Problem:#

Imagine you’re working on two projects:

If everything uses the same global Python, these versions will conflict.

The Solution:#

A virtual environment is like a self-contained Python workspace. Each project can:

It’s like giving each project its own sandbox so they don’t step on each other’s toes.


2. The Big 4: virtualenv vs venv vs pyenv vs conda#

ToolSupports Python 2?Built-in?Manages Python versions?Main Use
virtualenv✅ Yes❌ NoVirtual envs for Python 2 & 3
venv❌ No✅ Yes (3.3+)Basic virtual environments
pyenv✅ Yes❌ No✅ YesManage multiple Python versions
conda✅ Yes❌ No✅ YesData science, package + env management

3. How to Use Them (with Examples)#

Option 1: virtualenv – The Original Python Virtual Environment Tool#

History:

Key Features:

When to Use virtualenv:


1. Install it:#

Terminal window
pip install virtualenv

2. Create an environment:#

Terminal window
virtualenv myenv

3. Activate it:#

4. Exit:#

Terminal window
deactivate

Option 2: venv (Best for Beginners)#

History:

Key Features:

Good for:

1. Create a virtual environment:#

Terminal window
python -m venv myenv

2. Activate it:#

3. Install packages:#

Terminal window
pip install requests

4. Deactivate:#

Terminal window
deactivate

Now all packages (like requests) are inside myenv only.


Option 3: pyenv (Manage Multiple Python Versions)#

History:

Key Features:

Good for:

1. Install pyenv (macOS example):#

Terminal window
brew install pyenv

2. Install a Python version:#

Terminal window
pyenv install 3.10.6

3. Set it globally or per-project:#

Terminal window
pyenv global 3.10.6

(Optional) Use with pyenv-virtualenv plugin:#

Terminal window
pyenv virtualenv 3.10.6 myenv
pyenv activate myenv

Great for working on projects that need different Python versions.


History:

Key Features:

Good for:

1. Create an environment:#

Terminal window
conda create -n myenv python=3.10

2. Activate it:#

Terminal window
conda activate myenv

3. Install packages:#

Terminal window
conda install numpy pandas

4. Deactivate:#

Terminal window
conda deactivate

Conda environments come with Python and often install scientific libraries faster and more reliably.


4. Which One Should You Use?#

Your situationUse…
You’re a beginner or working on standard Python 3+ appsvenv
You work in data science / machine learningconda
You need to manage multiple Python versionspyenv (optionally with venv)
You need compatibility with Python 2 or advanced optionsvirtualenv