Python Virtual environments ! Why ? And how? conda? pip?....Explained clearly

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so what is a virtual environment in python in the real life when we have to do cooking we like to have a room called kitchen where we have a stu a pan clothes for washing hands and a lighter similarly when we want to take a shower we need a room called washroom where we may have towel and shampoo similarly when we want to sleep we want a room which has a bed and a blanket we are keeping three different rooms so that the items don't get mixed with each other similarly when we are creating projects in Python we don't want different versions of libraries to interact and break the code so that's why we create virtual environments where all the libraries are compatible with each other but to maintain these rooms or virtual environments and their tools or the libraries we need to understand VNV K and pip VNV and K are environment creators whereas K and pip they are package managers so in the example of a washroom the environment creator creates the washroom whereas the package manager puts the towel and shampoo inside the washroom and as you might have noticed K can perform as an environment Creator and as a package manager so how do we get these tools working on our computer so to get K on your computer we have two options we can install either anaconda or miniconda both these tools contain cond and some other libraries so you can install any of them and you will get cond working on your computer and if you have python installed on your computer V andv and pip come pre-built in Python so your computer can use them directly so now we know that to create a virtual environment we need a environment Creator and a package manager so what are the options that we have so we have these many options to use however K as an environment Creator and pip as a package manager is used very often because it has certain advantages you might think why not use K for both environment Creator and package manager however K has certain limitations as a package manager hence pip is preferred as a package manager so let us see how we can create three virtual environments named kitchen washroom and bedroom we will use cond which we can get from anaconda or miniconda as we discussed so I will fire up my miniconda prompt and and miniconda prompt comes with a base virtual environment and that is why we see the word base at the starting now I will create environments in a test folder on the desktop so I will change the directory to this test folder and then I will type cond create name whose name is kitchen and then press enter it will ask you yes or no to proceed you we'll write yes and then press enter and the kitchen environment has been created now similarly we will create the washroom environment so we'll write cond create-- name which is the washroom and then press enter then we repeat the same process for a virtual environment named bedroom now we can check which all virtual environments has been created by cont and we can do that by typing cond MV list so as you can see we have four virtual environments first being the base and the other three that we created just now that is bedroom kitchen and washroom and the star in front of Base means that this is the active environment that we are in presently so as you can see it's very easy to create an environment now if we want to move from our base environment to another environment we just write cond activate and then the name of the environment so now the word basee has changed to kitchen because the environment has changed to close this environment we'll write cond deactivate and then the cond will return to its base environment now suppose we want to enter the bedroom environment and write some code over there so we activate the bedroom environment and then write Jupiter notebook but this gives an error because in the bedroom environment there is nothing known as Jupiter which is installed so now we need to install packages and just like we discussed first we have options of using either K or pip as a package manager so let's see how we can install using K so we'll type cond install - c space cond Forge cond Forge is the repository and space notebook so notebook for jupyter Notebook and then we press enter this process will run for a few minutes and download all the files and after that the Jupiter Library will be installed in this environment so everything is done we again type Jupiter notebook inside the bedroom environment and wait for the execution and now we can see that Jupiter notebook has been launched without any error so that means that jupyter notebook has been installed in the bedroom environment now we close this and press contrl C which stops the Jupiter notebook now let us see whether installing jupyter notebook in the bedroom environment gives us a jupyter notebook in the other environment so we close this environment using cond deactivate and then activate the kitchen environment and run Jupiter notebook so as we can see there is no jupyter notebook in the kitchen environment because we did not install it so over here we'll use the other package manager that is pip or pip and then we'll type pip install Jupiter and then again it will download all the packages be sure to be connected to the internet and after a few minutes the Jupiter notebook will be installed in the kitchen environment also now if we again type Jupiter notebook we see that the notebook is launched so I hope this answered a few questions about virtual environments if you have any doubts please post them in the comments below
Info
Channel: Biomedical AI Basics
Views: 266
Rating: undefined out of 5
Keywords: python virtual environment, virtual environment, virtual environments, venv, virtualenv, python venv, python virtualenv, virtual environment python, learn python coding, learn python programming, python programming tutorials, What is virtual environment, what is anaconda python, how to install anaconda python, create a new virtual environment, using a virtual environment in python, what is pip, pip python, install package in python, install packages using anaconda
Id: zzY0iWWvuRk
Channel Id: undefined
Length: 5min 44sec (344 seconds)
Published: Sun Dec 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.