Virtual Environment In Python

ajaykushal4
Catalysts Reachout
Published in
3 min readSep 21, 2022

Data Science, Deep Learning, Machine Learning, and Artificial Intelligence are the trending topics in the field of computer technology. Day by day, the progress in these fields is increasing due to which it made our lives easier and more machine-dependent. To master these fields programming is a must and this is where Python has come into picture. Also it has a high range of popularity in web development, operating systems, mobile application development, video games, etc. Now let’s move towards Virtual environment and its purpose.

What is a virtual environment?

A virtual environment is a networked application that allows a user to interact with both the computing environment and the work of other users. Email, chat, and web-based document sharing applications are all examples of virtual environments. Simply put, it is a networked common operating space. A virtual environment is a simple tool that separates the dependencies of different projects by creating a separate isolated environment for each project. They are nothing but the directories, so that N number of virtual environments can be created. This is one of the popular tools used by most of the Python developers.

Why do we need a virtual environment?

Python has various modules and packages for different applications. During our project it may require a third-party library, which we install usually. Another project also uses the same directory for retrieval and storage but doesn’t require any other third-party packages. So, the virtual environment can come into play and make a separate isolated environment for both projects, and each project can store and retrieve packages from their specific environment.

Also, let us consider another case where we are creating a web application using any Framework. Suppose you are working on two projects 1 and 2. If 1 uses Framework-2.2 and 2 uses Framework-3.2, they would be stored in the same directory with the same name and error may occur. In such cases, virtual environments can be really helpful for us to maintain the dependencies of both the projects.

Working with a Virtual environment

To create a virtual environment, we need a module named virtualenv. It creates a folder with all the necessary executables to run Python projects.

Create a virtual environment

After successful installation of virtualenv, now you can create a virtual environment with your desired name. As an example, create X as the name of your virtual environment. You can name it whatever you desire. The folder with the name X is created which contains all the necessary executables to run the Python project. This is the folder where all your python packages will run.To specify the Python interpreter of your choice, you can do it by specifying Python{version-name}. After successfully creating the virtual environment, you need to activate it to enter into that particular isolated environment.

In Windows:

After activating the virtual environment, you can see your name of the virtual environment on the terminal’s left side. It confirms the activation of your virtual environment and is currently active.

Finally, you successfully created and activated your virtual environment. Now, you can install the dependencies and requirements your project asks for without interfering with other projects. Once you complete your work, then you can return to the system default environment by just using the deactivate command.

Advantages:

  • Cost savings
  • Easy provisioning
  • Increased productivity
  • Efficient DevOps
  • Environment-friendly IT operations
  • Full isolation means more security
  • Portability means that VMs can run old applications better.

THANK YOU
I will be back with good content again…

--

--