Virtualenv and venv: Python virtual environments explained

Take advantage of virtual environments in Python 2 and Python 3 to manage conflicts between Python projects

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

Of all the reasons Python is a hit with developers, one of the biggest is its broad and ever-expanding selection of third-party packages. Convenient toolkits for everything from ingesting and formatting data to high-speed math and machine learning are just an import or pip install away.

But what happens when those packages don’t play nice with each other? What do you do when different Python projects need competing or incompatible versions of the same add-ons? That’s where Python virtual environments come into play.

You can create and work with virtual environments in both Python 2 and Python 3, though the tools are different. Virtualenv is the tool of choice for Python 2, while venv handles the task in Python 3. 

What are Python virtual environments?

A virtual environment is a way to have multiple, parallel instances of the Python interpreter, each with different package sets and different configurations. Each virtual environment contains a discrete copy of the Python interpreter, including copies of its support utilities.

To continue reading this article register now