DevToolBoxFREE
Blog

Python Virtual Environments Guide: venv, conda, pipenv, and poetry

10 min readby DevToolBox

Virtual environments are the cornerstone of Python dependency management. Without them, packages from different projects conflict, system Python gets polluted, and reproducibility becomes impossible. This guide covers the four major tools — venv, conda, pipenv, and Poetry — with practical examples and recommendations for 2026.

Why Virtual Environments Matter

Every Python project has its own dependencies with specific version requirements. Project A might need Django 4.x while Project B needs Django 3.x. Without isolation, you can only have one version installed globally. Virtual environments solve this by creating isolated Python installations per project.

venv: Built-in Standard Library

venv is included with Python 3.3+ and is the simplest option. It creates a lightweight virtual environment with its own site-packages directory. No additional installation required.

# venv — Built-in (Python 3.3+)

# Create a virtual environment
python -m venv .venv

# Activate (macOS/Linux)
source .venv/bin/activate

# Activate (Windows)
.venv\Scripts\activate

# Install packages
pip install django requests

# Save dependencies
pip freeze > requirements.txt

# Install from requirements.txt
pip install -r requirements.txt

# Deactivate
deactivate

# Delete the environment
rm -rf .venv

# Recommended: add .venv to .gitignore
echo ".venv" >> .gitignore

Poetry: Modern Dependency Management

Poetry is the most modern and full-featured Python dependency manager. It handles virtual environments, dependency resolution, building, and publishing packages — all in one tool.

# Poetry — Modern Dependency Management (Recommended 2026)

# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -

# Create a new project
poetry new my-project
cd my-project

# Add dependencies
poetry add django
poetry add --group dev pytest black ruff

# Install all dependencies (from poetry.lock)
poetry install

# Run commands in the virtual environment
poetry run python manage.py runserver
poetry run pytest

# Open a shell in the virtual environment
poetry shell

# Update dependencies
poetry update

# Export to requirements.txt (for compatibility)
poetry export -f requirements.txt --output requirements.txt

# Build and publish a package
poetry build
poetry publish

# Show dependency tree
poetry show --tree

# pyproject.toml (auto-generated)
# [tool.poetry]
# name = "my-project"
# version = "0.1.0"
# description = ""
# [tool.poetry.dependencies]
# python = "^>=3.11"
# django = "^>=5.0"
# [tool.poetry.group.dev.dependencies]
# pytest = "^>=8.0"

conda: Data Science Powerhouse

conda is not just a virtual environment tool — it is a full package manager that can install non-Python dependencies (C libraries, CUDA, system packages). It is the standard in data science and machine learning.

# conda — Data Science / ML (Anaconda/Miniconda)

# Install Miniconda (minimal)
# https://docs.conda.io/projects/miniconda/

# Create environment with specific Python version
conda create -n myproject python=3.11

# Activate environment
conda activate myproject

# Install packages (conda packages first)
conda install numpy pandas scikit-learn matplotlib

# Install packages not in conda
pip install some-pytorch-extension

# Export environment
conda env export > environment.yml

# Create from environment.yml
conda env create -f environment.yml

# List environments
conda env list

# Deactivate
conda deactivate

# Remove environment
conda env remove -n myproject

# Update conda
conda update conda

# environment.yml example:
# name: myproject
# channels:
#   - conda-forge
#   - defaults
# dependencies:
#   - python=3.11
#   - numpy=1.26
#   - pandas=2.1
#   - pip:
#     - custom-package==1.0

Tool Comparison

Choosing the right tool depends on your use case.

Tool        Installation  Lockfile  Non-Python  Build/Publish  Best For
------------------------------------------------------------------------
venv        Built-in      No        No          No             Simple scripts, learning
pipenv      pip install   Yes       No          No             Legacy projects
Poetry      curl install  Yes       No          Yes            General apps, libraries
conda       Installer     Yes       Yes         No             Data science, ML, AI
uv          cargo/pip     Yes       No          Yes            Fast pip replacement (2026)

Frequently Asked Questions

Which virtual environment tool should I use in 2026?

For general Python development and web apps, use Poetry. It provides the best developer experience with lockfiles, dependency groups, and publishing. For data science and ML, use conda (or mamba for faster resolution). For simple scripts or when you want zero extra tools, use venv.

What is the difference between pip and conda?

pip installs Python packages from PyPI only. conda installs packages from the Anaconda repository and can install non-Python packages (C libraries, CUDA, Fortran libraries). pip works with any Python installation; conda manages its own Python as well.

Can I use pip inside a conda environment?

Yes, but with caution. Mixing pip and conda can sometimes cause conflicts. Best practice is to install as much as possible with conda first, then use pip only for packages not available in conda channels.

How do I share my environment with other developers?

With Poetry: commit pyproject.toml and poetry.lock. Other developers run "poetry install". With pip: run "pip freeze > requirements.txt" and others run "pip install -r requirements.txt". With conda: export with "conda env export > environment.yml".

Related Tools

𝕏 Twitterin LinkedIn
Was this helpful?

Stay Updated

Get weekly dev tips and new tool announcements.

No spam. Unsubscribe anytime.

Try These Related Tools

{ }JSON Formatter

Related Articles

Python Type Hints Complete Guide: mypy, Protocols, and Runtime Validation

Master Python type hints in 2026. Annotate functions and classes, use mypy for static checking, define Protocols, and validate types at runtime with Pydantic.

FastAPI Tutorial: Build REST APIs with Python in 2026

Complete FastAPI tutorial: setup, routing, request validation, authentication, database integration, testing, and deployment best practices.

Python Decorators Explained: From Basics to Advanced

Master Python decorators: function decorators, class decorators, decorators with arguments, functools.wraps, and real-world patterns for timing, caching, retry, and auth.