Python Virtual Environments Explained: venv vs uv vs conda
What a Python virtual environment is, why every project needs one, and how venv, uv and conda create them. Start here, then see the full comparison.
Every “install this and it broke my other project” problem in Python traces back to the same root cause: packages installed globally instead of isolated per project. Virtual environments fix that, and every packaging tool worth using is built around creating one.
What a virtual environment actually is
A virtual environment is a self-contained directory with its own Python interpreter (or a symlink to one) and its own site-packages folder for installed libraries, isolated from your system Python and from every other project’s environment. Activate it, and pip install requests puts requests only inside that folder — a different project with a different environment can have a completely different version of requests, or none at all, without conflict.
venv: built in, manual
venv ships with Python itself, so there is nothing to install. It is the baseline every tutorial assumes, so it is worth knowing end to end.
python3 -m venv .venv # create the environment in a folder called .venv
source .venv/bin/activate # activate it (macOS and Linux)
pip list # a new environment contains only pip
pip install requests # installs into .venv, nowhere else
deactivate # leave the environmentActivation prepends the environment’s bin folder (Scripts on Windows) to your PATH, so python and pip now mean the environment’s copies. The command depends on your shell, per the Python docs:
| Shell | Activate with |
|---|---|
| bash, zsh | source .venv/bin/activate |
| fish | source .venv/bin/activate.fish |
| csh, tcsh | source .venv/bin/activate.csh |
Windows cmd.exe |
.venv\Scripts\activate.bat |
| Windows PowerShell | .venv\Scripts\Activate.ps1 |
To check you are inside one, run python -c "import sys; print(sys.prefix != sys.base_prefix)". It prints True in a virtual environment, which is the test the Python docs recommend.
You don’t have to activate at all. Calling the environment’s interpreter by path does the same job: .venv/bin/python script.py or .venv/bin/python -m pip install requests use the environment even in a plain shell. Scripts installed into the environment carry a shebang line pointing at its interpreter, so they run without activation too. That is how editors, cron jobs and CI usually use one.
Dependency tracking is still manual: pip freeze > requirements.txt writes the exact versions currently installed, and pip install -r requirements.txt restores them.
uv: fast, integrated into a full workflow
uv creates and manages virtual environments as part of its broader project-management workflow — uv venv creates one directly, or more commonly you never think about it explicitly at all, since uv sync creates the environment and installs locked dependencies into it in one step. The underlying mechanism is similar to venv, but uv wraps it in tooling that also handles locking and dependency resolution, which plain venv doesn’t attempt.
conda: environments plus non-Python dependencies
Conda environments go further than the other two: alongside Python packages, conda can install and manage non-Python dependencies — compiled C libraries, other languages’ runtimes, specific compiler versions — inside the same isolated environment. That’s the entire reason it exists as a separate ecosystem from pip-based tools, and it’s specifically relevant for data science and ML work where a package needs system-level dependencies that wheels don’t bundle.
For a direct three-way comparison with commands, see uv vs venv vs conda.
uv vs conda: the short version
| uv | conda | |
|---|---|---|
| Installs Python itself | Yes, it can install and manage Python versions | Yes, Python is just another package |
| Non-Python dependencies (C libraries, R, compilers) | Only what is bundled inside Python wheels | Yes, this is its main strength |
| Replaces pip, pyenv, virtualenv | Yes, per uv’s docs | Does its own environment and package management |
| Best for | Pure-Python projects: web apps, CLIs, libraries | Scientific and data work with heavy native dependencies |
If your dependencies all come from PyPI, uv is the simpler, faster choice. Reach for conda when a package needs a native library that wheels don’t provide.
Alternatives to Anaconda
If you want to stay in the conda ecosystem but not use the full Anaconda distribution (see What Is Anaconda? for how the installers and licences differ), there are lighter options:
- Miniforge: minimal installers for conda and mamba with the conda-forge channel pre-configured as the default and only channel.
- micromamba: a tiny statically linked build of the mamba package manager. It needs no base environment, which makes it convenient in CI and Docker.
- pixi: a cross-platform, multi-language package manager built on the conda ecosystem. It always keeps a lock file, installs tools per project or system-wide, and is written in Rust.
If you only need Python packages, you can leave conda behind entirely and use uv with a standard virtual environment.
Keep it out of Git, and rebuild it instead of copying it
A virtual environment is disposable. The Python docs say it should not be checked into source control and should be easy to delete and recreate, and that it is not movable or copyable.
- Git: since Python 3.13,
venvwrites a.gitignorecontaining*inside the environment folder, so Git ignores it with no setup on your part. uv does the same. On older Pythons, add.venv/to your project’s.gitignore. - Moving or copying breaks it. Installed scripts record the absolute path of the environment’s interpreter. Moving the folder and running its
pipgavebad interpreter: ... no such file or directory. Create a fresh environment in the new location instead. - Rebuild from a list of dependencies. With plain
venv, that ispython3 -m venv .venvthen.venv/bin/python -m pip install -r requirements.txt. With uv and apyproject.toml,uv synccreates.venvand installs the locked versions. For how the two formats differ, see requirements.txt vs pyproject.toml. - What it remembers: the environment’s
pyvenv.cfgrecords which interpreter and Python version created it, and whether it can see the system’s packages (include-system-site-packages = falseby default).
Common problems
error: externally-managed-environment. A system or Homebrew Python refusespip installoutside an environment. Create a virtual environment and install there. The full explanation is in fixing the externally-managed-environment error.- You installed a package but still get
ModuleNotFoundError. The code is running under a different interpreter from the one you installed into. Comparewhich python(orwhere pythonon Windows) with where you ranpip install, and make sure your editor is pointed at the environment’s interpreter. Runningpython -m pip installrather than barepipkeeps the two in step. See ModuleNotFoundError: No module named. - PowerShell refuses to run
Activate.ps1. Windows may block the script. The Python docs give the fix: runSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUseronce, then activate again. - Packages appear in the wrong project. You probably forgot to activate, or activated another project’s environment. The prompt prefix (the environment’s name in brackets) shows which one is active.
Which one to use
For a typical web app, CLI tool, or library with only Python dependencies: uv, and let it manage the virtual environment for you as part of the wider workflow — see our packaging tools guide for the fuller picture. Plain venv is worth knowing because it’s what every tutorial assumes as a baseline and requires no installation, but it’s rarely the best choice once you have an alternative available. Reach for conda specifically when your project has non-Python system dependencies conda’s package management genuinely solves — most projects don’t.
Frequently Asked Questions
What is a Python virtual environment?
A self-contained directory with its own Python interpreter and its own site-packages folder for installed libraries, isolated from your system Python and from every other project’s environment — so different projects can use different versions of the same package without conflict.
uv vs conda: which should I use?
uv for projects whose dependencies all come from PyPI; it is simpler and can also install Python versions. conda when you need native, non-Python dependencies that wheels do not provide, which is common in scientific and data work.
What are good alternatives to Anaconda?
To stay with conda, Miniforge (conda-forge by default), micromamba (a tiny executable with no base environment) and pixi (a conda-based tool with built-in lock files). If you only need Python packages, uv with a standard virtual environment avoids conda altogether.
What’s the difference between venv, uv, and conda?
venv ships with Python and requires manual dependency tracking. uv creates and manages environments as part of a full workflow including locking and dependency resolution. Conda additionally manages non-Python dependencies like compiled C libraries and other languages’ runtimes.
Which one should you use?
uv for a typical web app, CLI tool, or library with only Python dependencies — it manages the virtual environment for you as part of its wider workflow. Reach for conda only when your project has non-Python system dependencies it genuinely solves.
Do you need conda for data science work?
Only if you need conda’s ability to manage non-Python system dependencies, such as native scientific libraries and toolchains that are not packaged as Python wheels. Many GPU libraries now install from wheels instead: PyTorch pulls its CUDA libraries from PyPI. Most data science projects with only Python dependencies don’t need it.
How do you activate a Python virtual environment on Windows?
In cmd.exe run .venv\Scripts\activate.bat; in PowerShell run .venv\Scripts\Activate.ps1. If PowerShell blocks the script, the Python docs say to run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser once. On macOS and Linux with bash or zsh it is source .venv/bin/activate.
Should you commit a virtual environment to Git?
No. A virtual environment is disposable and tied to the machine and path it was created in, so you commit the dependency list (requirements.txt, or pyproject.toml and a lock file) and recreate the environment from it. Since Python 3.13, venv adds a .gitignore inside the environment so Git ignores it automatically.
Do you have to activate a virtual environment to use it?
No. Running the environment’s own interpreter by path, such as .venv/bin/python script.py, uses the environment without activating it. Activation only puts its bin folder first on your PATH so that python and pip mean its copies.