Virtual Environments and pip
I will add that creating and removing conda
environments is simple with Anaconda.
> conda create --name <envname> python=<version> <optional dependencies>
> conda remove --name <envname> --all
In an activated environment, install packages via conda
or pip
:
(envname)> conda install <package>
(envname)> pip install <package>
These environments are strongly tied to conda's pip-like package management, so it is simple to create environments and install both Python and non-Python packages.
Jupyter
In addition, installing ipykernel
in an environment adds a new listing in the Kernels dropdown menu of Jupyter notebooks, extending reproducible environments to notebooks. As of Anaconda 4.1, nbextensions were added, adding extensions to notebooks more easily.
Reliability
In my experience, conda
is faster and more reliable at installing large libraries such as numpy
and pandas
. Moreover, if you wish to transfer your preserved state of an environment, you can do so by sharing or cloning an env.
Comparisons
A non-exhaustive, quick look at features from each tool:
Feature |
virtualenv |
conda |
Global |
n |
y |
Local |
y |
n |
PyPI |
y |
y |
Channels |
n |
y |
Lock File |
n |
n |
Multi-Python |
n |
y |
Description
virtualenv
creates project-specific, local environments usually in a .venv/
folder per project. In contrast, conda
's environments are global and saved in one place.
- PyPI works with both tools through
pip
, but conda
can add additional channels, which can sometimes install faster.
- Sadly neither has an official lock file, so reproducing environments has not been solid with either tool. However, both have a mechanism to create a file of pinned packages.
- Python is needed to install and run
virtualenv
, but conda
already ships with Python. virtualenv
creates environments using the same Python version it was installed with. conda
allows you to create environments with nearly any Python version.
See Also
In my experience, conda
fits well in a data science application and serves as a good general env tool. However in software development, dropping in local, ephemeral, lightweight environments with virtualenv
might be convenient.