Python developers make heavy use of external libraries to add features and fix bugs. Depending on the complexity of the issue at hand you will need different versions of each tool. It can get tricky to use tool X (which uses the newest version of framework Y) to fix a problem when another project you are working on needs an outdated version of the framework because of the way its dependencies are set up. This is a common problem that can be handled with virtual environments.

Here’s an in-depth comparison of the most popular virtual environment tools to help you decide.

The definition of virtual environments according to Python docs is,

A cooperatively isolated runtime environment that allows Python users and applications to install and upgrade Python distribution packages without interfering with the behaviour of other Python applications running on the same system.

Virtualenv

Pros

  • Virtualenv is the most common and easy to install tool for virtual environments. It’s a great tool for beginners.
  • Easy to use in the deployed environments.
  • The most common tool for python virtual environments, so it has lots of documentation for many issues.

The following commands will give you a better understanding of the way it works,

Cons

  • Due to its simplicity, it doesn’t have a lot of features or functionalities. 
  • You have to install it separately from the Python packages.
  • You need to change constantly your path in order to activate and deactivate your virtualenv.

There’s an extension called virtualenvWrapper that adds more features to manage your environments easily.

Pipenv

Pipenv is a tool used for managing virtual envs and packaging in Python. It’s aimed to integrate the functionality of Pip and Virtualenv in one single tool and claims to bring the best of every packaging tool to the Python world.

Pros

  • It has advanced features and functionalities to create, delete, activate, and deactivate your environment.
  • It uses a Pipfile.lock file to handle all the packages installed. This enhances the simplicity of installing dependencies from other projects since the only thing you need to have the project’s file and execute a simple command.
  • Can graph the dependencies with a simple command.
  • Pipenv includes the safety package and scans every package in your dependencies to find security vulnerabilities.
  • With the pipenv open command, you can open the package project to see the source code of your dependencies.
  • With Pipenv, you don’t have the problem of having to change your file path to activate your Virtualenv.

Cons

  • It has a steep learning curve for beginners.
  • It also can be very confusing to use a more complex tool for something that doesn’t need the majority of Pipenv functionalities.

Conda

Anaconda is a package management library for deployment. It also comes with a lot of scientific Python libraries for machine learning, artificial intelligence, big data libraries, etc.

Anaconda comes with a package and environment manager called conda, which can be defined as,

Package, dependency and environment management for any language—Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN, and more.

Pros

  • It has built-in support for package management. 
  • Its packages are binaries so you never have to install compilers to use any of them. Even though this is not related to the virtual environment functionality, is definitely nice to have. 
  • It supports every functionality that traditional Virtualenv libraries have. 
  • You can have different versions of Python installed, each being isolated from the others and all in one single tool. 

Usually, to get all these functionalities in Python, you have to use more than one tool. The basic functionality of conda is illustrated here,

Cons

  • Conda is the right virtual environment tool only if you plan to use Anaconda suite for a while. This suite is very big.
  • Most tools don’t accept conda environments at least as smoothly as pip requirements

 Using miniconda can be a better option.

Finally…

Don’t go into a long term relationship with any specific framework or library, the best idea is to try every option at least once. There’s no such thing as a magic tool for every kind of problem, having several alternatives on hand will help you for every kind of issue.

If you have any questions please contact me at [email protected]