What is the difference between virtualenv, pipenv & venv?

What is the difference between virtualenv, pipenv & venv?

Python is beautiful, so its virtual environment tools

Note: If you are looking for a Full Stack Developer (Django+React), then connect with me on LinkedIn or contact me through my portfolio.

Introduction:

virtualenv, pipenv, venv all serves the same purpose, isolating your third party packages installed by Python package manager pip in a virtual environment, separated from your system level Python dependencies.

But they have certain set of differences in terms of the way how they store your environments and also the speed at which they complete the task for you.

virtualenv:

It is the by far the most used virtual environment tool to manage your pip packages in an isolated environment.

It works by installing a bunch of files in a directory (e.g. env/), and then modifying the PATH environment variable to prefix it with a custom bin directory (e.g. env/bin/).

To use it, all you have to do is install it, create an environment, then activate it, and you are ready to install the pip packages.

To share your pip packages across multiple systems, we need to create a requirements.txt file, which can be easily done with this command:

pip freeze > requirements.txt

pipenv:

pipenv is similar to virtualenv, it has one extra feature, which is Pipfile, Pipfile is similat to what we see as packages.json in npm.

Pipfile contains all the installed packages in the current environment, and automatically updates itself if you install a new package inside the same environment.

Although in my personal opinion, pipenv is kinda slow compared to virtualenv but it comes with some extra features.

Basically, pipenv aims to combine Pipfile, pip and virtualenv into one command.

venv:

It serves the same purpose as virtualenv, but only has a subset of its features. As per official docs:

*venv provides support for creating lightweight virtual environments with their own site directories in isolation.*

In many Linux distributions, venv comes preinstalled with Python 3, you can verify it using this command:

python3 -m venv -h

Conclusion:

All of them are good, go for virtualenv as it is most easy to use, and efficient tool. Otherwise, you have other choices, spend some more time with each of them, even there are some more like pyenv , pyenv-virtualenv, virtualenvwrapper etc.

It's your personal choice, but you give a try to at least few of them.

For more such crispy blogs daily, follow Dev.Junction, subscribe to our newsletter and get notified.

Did you find this article valuable?

Support Dev.Junction by becoming a sponsor. Any amount is appreciated!