Python : What is Virtual Environment

Each project might need some set of dependencies with their specific version to work properly. Usually, we might have multiple projects running on different versions / packages. For example

  • some project on python2 others python 3
  • some project using pymongo2.7 others pymongo3.2

Normally, we have installed python 2.7, then we might not run python3 without upgrading to python3, however there is solution called virtual Environment which allows us to have an environment for specific required for each project and it is called as virtual environment. This can be installed using below command

$ [sudo] pip install virtualenv

The trick is to create separate folder for each project and activate virtual environment over there, that way requirements might not clash with each other. 

for example, i have 2 projects named make_money and spend_money wh

So I have to make 2 different directories and install virtual environment in them, I can run my project from any where, however the dependencies would be installed in that specific project. 

It is kind of similar to NPM for node, and pip is similar to maven in java

Helpful link : https://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s