Skip to content
Go back

Creating Python Virtual Environments

Updated:
Creating Python Virtual Environments

Note (2025): This post was originally written in 2021. The method described here using venv is still the standard way to create virtual environments in Python today. Alternatives such as Poetry, Pipenv, and Conda may also be used depending on your workflow, but venv remains the simplest, built-in option.


Table of Contents

Open Table of Contents

Creating a Virtual Environment

Choose a directory where you want to keep your environments:

$ mkdir Playground
$ cd Playground

Create a new environment named learning_env:

$ python3 -m venv learning_env

This creates a new directory with:

Together, these isolate your project’s dependencies from the global system.

Activating the Environment

Activate the environment with:

$ source learning_env/bin/activate

Your shell prompt will now include the environment name:

(learning_env) $

Inside the environment, you can just use python or pip and pip (no need for python3 or pip3).

Using the Environment

Check the Python version:

(learning_env) $ python --version
Python 3.9.1

Install packages as usual:

(learning_env) $ pip install requests

Everything is installed inside learning_env, isolated from your global Python.

Deactivating

When you’re done, type:

(learning_env) $ deactivate
$ python --version
Python 2.7.16   # back to system default

Modern Alternatives (2025)

While venv remains reliable, developers today also use:

For most apps, though, the built-in venv is the simplest and most portable choice.


Quick Comparison

ToolBuilt-in?Best ForProsCons
venv✅ YesGeneral projects, simple setupsLightweight, no extra installs, universalNo dependency resolution, just isolation
Poetry❌ NoModern app development, packagingLockfile, publishing support, dependency managementExtra tool to install, opinionated
Pipenv❌ NoLegacy projects, Pipfile workflowIntegrates pip + virtualenv, human-friendly configPopularity declined, slower than Poetry
Conda❌ NoData science, ML, scientific computingHandles Python + native libs (e.g., BLAS)Heavyweight, separate ecosystem

Wrap-up

Virtual environments solve the problem of conflicting dependencies by isolating projects. Whether you use venv, Poetry, or Conda, it’s a best practice to never develop Python projects in your system Python installation.


Share this post on:

Previous Post
Centering a Fixed-Sized Element with CSS
Next Post
Fixing Homebrew & Zsh Issues After macOS Upgrades