W3docs

What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc?

There are many different tools that you can use to create isolated Python environments, each with their own benefits and drawbacks.

There are many different tools that you can use to create isolated Python environments, each with their own benefits and drawbacks. Here is a brief overview of some of the most popular ones:

  • venv is a built-in Python module that provides support for creating lightweight, isolated Python environments. It is included in Python 3.3 and later versions.

  • pyvenv was a script included in Python 3.3–3.9 that provided the same functionality as the venv module. It was deprecated in Python 3.6 and removed in Python 3.10. Modern Python versions use python -m venv instead.

  • pyenv is a third-party tool that allows you to easily install and manage multiple versions of Python on your system. It does not provide support for creating isolated environments, but it can be used in conjunction with virtualenv or pyenv-virtualenv to achieve this.

  • virtualenv is a third-party Python package that provides support for creating isolated Python environments. It is a popular choice for working on multiple projects that might require different package versions.

  • virtualenvwrapper is a set of shell scripts that provide additional functionality on top of virtualenv. It makes it easier to create and manage multiple virtual environments, and provides some additional features such as the ability to set environment variables for an environment, or to specify which Python interpreter should be used when creating a new environment.

  • pipenv is a packaging tool for Python that aims to bring the best of all packaging worlds (bundled, required, and development) to the Python world. It automatically creates and manages a virtual environment for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates the Pipfile.lock, which is used to produce deterministic builds.

Here is an example of how you might use the venv module to create a new isolated Python environment:

Create a new isolated Python environment using the venv module

python3 -m venv myenv

This will create a new directory called myenv that contains a self-contained Python installation, as well as a copy of the pip package manager.

To activate the environment, you can use the following command:

Activate an environment command

source myenv/bin/activate

This will modify your shell's environment variables so that the python and pip commands refer to the isolated Python installation and package manager. You should see the name of your environment in the command prompt, like this:

(myenv) $ command

To deactivate the environment and return to the global Python installation, you can use the following command:

Deactivate a Python environment

deactivate

Here is an example of how you might use virtualenv to create a new isolated Python environment:

Use virtualenv to create a new isolated Python environment

pip install virtualenv
virtualenv myenv

The first command installs the virtualenv package, and the second command creates a new directory called myenv that contains a self-contained Python installation, along with pip and other standard library tools. To activate it, run source myenv/bin/activate (or myenv\Scripts\activate on Windows).

Quick Comparison

ToolTypePrimary Use
venvBuilt-inStandard isolated environments (Python 3.3+)
virtualenvThird-partyIsolated environments (pre-3.3 or advanced features)
pyenvThird-partyManaging multiple Python versions
virtualenvwrapperShell scriptsManaging multiple virtualenv instances
pipenvThird-partyDependency & environment management (Pipfile)