One of the biggest draws of Python is its expansive ecosystem of third-party packages. If there is a task you want to pull off—file format conversion, scraping and restructuring web pages, linear regression, you name it—odds are that one or more packages in the Python Package Index will fill your need.
The hard part is managing the accumulation of packages in a given Python installation. It’s all too easy to thoughtlessly install dozens of packages and in time end up with a Python environment fraught with conflicts between older and newer versions of tools, making work harder than it needs to be.
Python comes with an automated system for keeping a package set local to a given Python project. Virtual environments—courtesy of the
virtualenv tool in Python 2 and
venv in Python 3—can be used to create a separate, isolated instance of the Python runtime for a project, with its own complement of packages.
In this article we’ll walk through some of the common mistakes people make—and gotchas they succumb to—when working with virtual environments in Python.