Note (2025): This post was originally written in 2021. The method described here using
venvis 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, butvenvremains 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:
pyvenv.cfg— points to the Python installation usedlib/— contains the Python version and site-packages for installed librariesinclude/— for compiling packagesbin/(Unix/macOS) orScripts/(Windows) — contains the Python binary and activation scripts
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:
- Poetry → dependency management + virtualenv + packaging in one
- Pipenv → manages
Pipfileand/Pipfile.lockautomatically - Conda → great for data science, handles Python + non-Python packages
For most apps, though, the built-in venv is the simplest and most portable choice.
Quick Comparison
| Tool | Built-in? | Best For | Pros | Cons |
|---|---|---|---|---|
| venv | ✅ Yes | General projects, simple setups | Lightweight, no extra installs, universal | No dependency resolution, just isolation |
| Poetry | ❌ No | Modern app development, packaging | Lockfile, publishing support, dependency management | Extra tool to install, opinionated |
| Pipenv | ❌ No | Legacy projects, Pipfile workflow | Integrates pip + virtualenv, human-friendly config | Popularity declined, slower than Poetry |
| Conda | ❌ No | Data science, ML, scientific computing | Handles 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.