What is virtual environment and how to use it in python? - CodingIndia

A virtual environment is a tool that helps to keep dependencies required by different projects

separate by creating isolated python virtual environments for them.

This is one of the most important tools that is used by most of the developers.

Why do we need Virtual environment?

When we are working with different versions of the same library or framework then we

need to use virtual environment. Virtual environment helps us to separate the different

projects and their dependencies.

What you need to do?

Virtual Environment should be used whenever you work on any Python

based project. It is generally good to have one new virtual environment

for every Python based project you work on. So the dependencies of every

project are isolated from the system and each other.

How to Install and use Virtual Environment?

We need to install module named - "virtualenv

". It will create a folder which contains all the necessary executables to use the

packages that a Python project would need.

                                                     pip install virtualenv     

Test your installation:

                                           virtualenv --version      

Creating the Virtual Environment:

                                                 virtualenv file_name       

Activating the Virtual Environment:

                                          file_name/bin/activate        

Now you can install any library and packages according to your project requirement and use it.

EX:- Try to install Django

                                                pip install django     


It will install django only in your virtual environment.

Deactivating the Virtual Environment:

for deactivating you have to just type deactivate

              deactivate                  


Now you can start your work and enjoy it.


Comments

  1. I appreciate you taking the time and effort to share your knowledge. This material proved to be really efficient and beneficial to me. Thank you very much for providing this information. Continue to write your blog.

    Data Engineering Services 

    Machine Learning Services

    Data Analytics Services

    Data Modernization Services

    ReplyDelete

Post a Comment