Understanding Virtual environments

Understanding Virtual environments

Throughout my journey, I’ve taught Python programming to many beginners. Helped them reach an intermediate level in terms of solving coding challenges, and understanding data structures and algorithms. But when it comes to building their projects, they all make the same mistake. They install their libraries globally.

As a beginner, it’s a very reasonable mistake to do. But when you are working on something at an organizational level, your code must work smoothly in everyone’s machines without affecting their other codes. Using virtual environments is a highly recommended practice by almost every senior programmer. With the help of virtual envs, you can easily install libraries without affecting the global environment. Moreover, you can install specific versions of libraries. If installed globally otherwise, There might occur some dependency issues where one script requires a different version of a library while the other requires a different one. But when you have two separate envs for each of the scripts, You can easily shift between the environments and run the scripts without any dependency errors.

Creating a Virtual environment is fairly easy. Simply go to the directory where you want to create your virtual environment. It’s almost always recommended to create it in the folder same as the project files. To create a virtual env, simply use the command “virtualenv env” and then you can find a new folder named env in that directory. You can use any name instead of env. For example, TO create an environment named my_env_1, simply type “virtualenv my_env_1”. To activate the environment, type “source env/bin/activate”. Or in this case, “source my_env_1/bin/activate”. You should see the name of the environment at the beginning of your path, in the terminal. Like so:

You can now easily pip install any library you want to and it will be confined to the activated environment. To deactivate this environment, simply type “deactivate”

The above-mentioned commands might be a bit different from the windows command prompt. But quite similar to anaconda environments. More on that later.




Looking for my next opportunity to make change in a BIG way

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Desi done right

Discovery Metrics: How to quantify the effectiveness of your discovery efforts

First steps outbox edu prep 4

Weekly report — — 21.03.2022–27.03.2022

JXL and Easy Agile, better together

Let us Git?

What is Snowflake?

The Troolian — Creativity in Coding

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sairam Penjarla

Sairam Penjarla

Looking for my next opportunity to make change in a BIG way

More from Medium

Spatial Experiences

Part 2 [MCDM]: Analytic Hierarchy Process (AHP) in 3 steps!

Kruskal’s Spanning Tree Algorithm