In our previous article, we discussed how to install python 3 on centos/rhel. In this article, we will see what exactly python virtualenv
is and the situation where it comes in handy. In the world of Python virtualenv
is the most recommended way of working.
What is python virtualenv?
virtualenv
is a tool to create isolated Python environments. virtualenv
creates a folder which contains all the necessary executable to use the packages that a Python project would need. When it is initiated, it automatically comes with its own Python interpreter – a copy of the one used to create it – alongside its very own pip.
Why is python virtualenv need for your application?
The basic problem being addressed is one of dependencies and versions, and indirectly permissions. If you have an application that needs version 1 of any python library, but another application requires version 2. How can you use both these applications?
There are a number of problems that virtualenv
solves:
- Creating a fresh, isolated environment for a Python project
- Being able to download packages without requiring admin/sudo privileges
- Easily packaging an application
- Creating a list of dependencies which belongs to a single project created with pip
- Easily recovering the dependencies using a requirements file created with pip
- Giving way to portability across systems
Using virtualenv
is the recommended way for working with Python projects.