Python Virtual Environments — The Definitive Guide
Let's find out how you can manage different python version on your system and portable projects …
Python Virtual Environments — The Definitive Guide

Different environments in light bulbs as flowers on a plant
Have you ever run into a situation where someone sends you a Python project that won’t run on your machine, even though they insist, “It works on my system” or vice versa when you share your own project?
I know we have all been there. This happens because the project was developed on the system-wide installation of Python, and packages needed were left to the receiver to decipher from the imports. Moreover, don’t even bother trying to guess which Python version was used — you’d practically need to know what machine the developer owns and when they bought it.
Fortunately, there is an easy solution for this problem, enter virtual environments. As the name suggests, these Python environments are not global that use the system level Python installation, whose version is usually outdated and has an endless list of packages installed on it since the machine was acquired. These environments can have any version of Python, and only those packages are installed that are required by the project.
In this article, we will go over the most widely used tools for environment management in Python and go over their pros and cons.
We will explore the five main methods of managing the Python environment: venv (the built-in standard), virtualenv (the classic alternative), pyenv (the version manager), conda (the data science heavyweight), and uv (the newcomer).
- The Built-in Standard
venv
This is the simplest and the standard option. It has been part of Python standard library since version 3.3 so it does not need any additional installation.
It creates a lightweight directory containing the environment’s own Python executable and package directory.
Pros: Zero installation overhead and universally supported.
Cons: Only manages environments, not the Python version. It's up to you to have the desired Python version installed.
Workflow
- Creation:
python3 -m venv my_project_env - Activation:
source my_project_env/bin/activate - Deactivation:
deactivate - Usage: Install packages (
pip install package_name), generate requirements (pip freeze > requirements.txt).
2. The Classic virtualenv
Thought virtualenv is the predecessor to venv it is actually the powerful alternative. It's slightly faster and more flexible, and is still actively maintained.
You can create environments for Python 2 and 3, though less relevant now that Python 2 is deprecated.
Pros: You can create environments more quickly than venv in some cases and provides some customization options, such as the --always-copy flag in virtualenv that forces the tool to make a complete copy of the interpreter and its supporting files to create a fully self-contained environment.
Cons: Requires separate installation.
Workflow
- Installation:
pip install virtualenv - Creation:
virtualenv my_project_env - Activation:
source my_project_env/bin/activate - Deactivation:
deactivate - Install packages using
pip
3.Managing Multiple Python Versions pyenv
This is the best choice for someone who works across multiple Python releases (e.g., 3.8, 3.10, 3.12). It's essentially a version manager that allows you to install, switch, and manage multiple Python interpreters on your system easily.
Pros:
- Avoids interference and conflicts from system level directories and Python version by installing in user's home directory.
- Works seamlessly with standard environment creation tools like
venv,virtualenv, and the fast, modernuv. - Using the
pyenv-virtualenvplugin allows you to create named environments that are stored centrally but can be activated/referenced from any project directory on your system.
Cons:
- Needs
pyenvinstallation and configuring shell's initialization files. - A separate official plugin,
pyenv-virtualenv, which needs to be installed alongside the corepyenvtool for virtual env creation. - Compiles Python versions from source, and this often requires you to manually install OS-level build dependencies (like
openssl,zlib,readline, etc.). If those dependencies are missing or incompatible, you may need to resolve compilation errors yourself.
Workflow
- Installation via Homebrew:
brew install pyenv pyenv-virtualenv - Install a Python Version:
pyenv install 3.13.10 - Set Local Version:
pyenv local 3.13.10(current directory) - Create an Environment:
pyenv virtualenv 3.13.10 myenv - Activate:
pyenv activate myenv - Deactivate:
deactivate - Install packages using
pip
- The Data Science Powerhouse
conda
The conda option is a full-featured package and environment manager and is primarily used in the scientific Python community where they deal with complex binaries, scientific packages, or non-Python dependencies.
It manages not only python packages, but also system-level dependencies and interpreters.
Pros: Excellent handling of complex scientific libraries, manages non-Python packages. In addition, it can also create global environments like pyenv.
Cons: Larger installation footprint is way too large, and environment creation is slower than venv/virtualenv.
That's why it doesn’t make sense to use it unless your projects need it.
Workflow
- Installation: Multiple options 🔗
- Creation:
conda create --name myenv python=3.13 - Activation:
conda activate myenv - Package Install:
conda install numpy pandas
5. The Modern Speedster uv
It is a highly optimized tool designed to replace pip and accelerate environment creation and dependency resolution. A native Rust-based package and environment manager.
It is exceptionally fast at resolving dependencies and installing packages, often beating pip and conda by orders of magnitude.
Pros: Its unmatched speed for dependency resolution and package installation has made it very popular.
Cons: As it is relatively new, so it may not yet fully cover every niche use case or integration method that older tools do.
Workflow
- Installation:
brew install uvor viacurl. - Creation:
uv venv myenv - Activation:
source myenv/bin/activate - Package Install:
uv pip install package_name
Global Environments
Global environments are nothing but environments that are created or located at some common location on a system and can be accessed or referenced in any project. In contrast, local environments are created in project folders and usually used only by the parent project.
Local Environments - venv, virtualenv, uv
- These tools are primarily designed to create the environment directly within the project’s root directory.
- A benefit of this approach is that it makes the project, and it’s environment, completely self-contained and portable.
Global (Centralized) Environments - pyenv and conda
Conda
- Conda environments are always stored globally in a central directory
(e.g., ~/miniconda3/envs).
- They are activated by name regardless of your current directory, making them excellent for shared utilities or data science notebooks.
pyenv
- pyenv environments are also created and registered globally in a central directory
~/.pyenv/versions. - You can then link this named environment to any project using the
pyenv local <name>command, effectively allowing a centralized environment to be used per-project without being stored locally.
My Preferred Option
Out of these 5 options, my go-to Python version and package manager is pyenv.
The two main reasons I got stuck on the pyenv after I tried it for the first time are:
- The ease at which you have to manage different python versions, not just the major versions but also the minor and the patch numbers.
- The central location at which all virtual environments get installed and the ease with which you can reference them to your project.
It is really helpful when you want to try building a project with a different python version or create a virtual environment and use to in multiple clones of a project repository during development.
It is really helpful in conserving disk space on your local system and clean up is easy as well because you can list all the virtual environments using a single command pyenv versions.
Finally, here is a comparison chart of the five methods we went over in this article.

Summary table of the five methods
Depending on your requirements, you show now be able to set up a Python development environment in minutes.
If you like this article, you might be interested in some of the other articles I wrote.
[embed]Hashable Objects in Python How to make any object unique for comparison?arccoder.medium.com
메타데이터
- post_id
- cd7945e5d7d8
- slug
- python-virtual-environments-the-definitive-guide-cd7945e5d7d8
- url
- https://medium.com/@arccoder/python-virtual-environments-the-definitive-guide-cd7945e5d7d8
- canonical_url
- https://medium.com/@arccoder/python-virtual-environments-the-definitive-guide-cd7945e5d7d8
- author_url
- https://medium.com/@arccoder
- status
- ok
- fetched_at
- 2026-06-29 01:02:39