Creating a Python Virtual Environment -- Step-by-Step Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so hey everyone welcome back to the channel in this video we are going to see what is the python virtual environment why we need python virtual environment how to set up python virtual environment how to activate deactivate python virtual environment for demonstration purpose or explanation I am going to show you what the python virtual environment actually is so just imagine you are working on your system and you have installed Python and you are working on a project such as a web application you are working and in that web application just imagine that you are working with python 3.8 okay and you can see this big square is the your global environment and the small square in it is the libraries folder for the python and in that you have various libraries such as you can say you have flask you have pandas etc etc so just imagine for your project or your website project you are using pandas 1.8 right and suddenly you are also you've gotten a new idea and you start working on a new project by watching the project on GitHub and you clone that project okay and what if that project is you also using the pandas library but it's using the latest pandas version that is 2.1 okay and here there are some deprecation in uh 2.1 version which are not available in previous version so if you update the pandas library then your web application won't work and if you won't update the library in that case your new application is not going to work right so you can see in this scenario virtual environment comes for our help so the new Big square box right now is our virtual environment okay so I am going to name it as v e and V and the small square box in it is the libraries folder for this new virtual environment okay so let's imagine that we are working in our new virtual environment uh with the new version of python such as python 3.11 okay and for our web application we are working with the version of python that is python 3.8 because we we were working uh from like the beginning of your career Okay so these are the two different versions of python as well as as I told you in the libraries also you are the Clone project using the latest libraries of pandas so it uses pandas 2.1 okay so now you can see python virtual environment actually creates a new virtual environments or new boxes where you can install libraries totally newly and they don't interfere with your Global installation and Global libraries right so you can manage multiple projects and multiple dependencies so I am going to open my terminal to show you some things so first of all where python this is the command with the help I am going to show you these are the two locations in my system where the python is installed so let's use the command pip space list so it will list all the libraries available in my global environment you can see MySQL connector for python pip and setup tools these three libraries are available in my global environment of python and let's create a new project folder so you can see I have created it on my desktop and let's open the new terminal in this project folder so for that just type CMD in the resource bar of your Explorer so you can see I have opened a new terminal in my projects folder I am just going to zoom it so you can see it easily so okay so this is the project folder now we want to create a virtual environment how we can create so use the command python Dash m v e n v for virtual environment so space dot slash because of we want to create in this directory and name the folder or name your virtual environment so algo algo is my virtual environment and just hit enter so you can see it's processing behind the scene it's creating some directory some files some scripts behind the scene so now our virtual environment is created and I will show you this is my projects folder or projects directory and you can see one new directory or named algo is created here if I open the algo directory you can see indicate then you can see libraries and scripts folder there in the scripts folder you can see activate deactivate and some python files are available right so we have created our python virtual environment so let's activate our virtual environment for that we need to go to the scripts folder so CD space I'll go and uh with the help of dir command I am going to list all the directories and files in algo folder you can see there is a script directory so CD space scripts so right now I am in scripts directory and I will again do dir and you can see there is one file activate dot bat so run activate for that you need to specify the name activate and press enter okay now we are in our new python virtual environment you can see there is a in parenthesis before the path algo name is there it indicates that we are in our algo python environment our new virtual environment okay so I am going to show you the list so pip list and you can see in this new virtual environment I have only pip and setup tools installed if I show you my previous window you can see here MySQL connector is also installed in my Global setup but that is not present in algo and you can see there is nothing present such as algo in front of path in my previous command or previous terminal window okay so I am going to install one new library so pip install pandas and you can see pandas library is getting installed so let's wait a moment for installation of pandas okay the pandas library is installed and I am going to list the libraries now so pip list and you can see numpy pandas and some other libraries like Pi TZ etc etc are available now foreign s are available and let's deactivate so for deactivating you just need to run the deactivate.bat and you will you are out of your virtual environment right so I will open a new terminal and again do a pip list so you can see uh there is nothing after deactivation you can see your Global installation and Global libraries okay so how we can delete the virtual environment that is again a question so it's nothing it's just a simple it's not a rocket science so you just need to delete this algo folder just hit on it and once the algo folder is deleted your python virtual environment is getting deleted so this is all for this video I hope this video will helpful for you if you find this video helpful then don't forget to like share and subscribe to our Channel we will meet you in the next video with some awesome content till then Happy coding
Info
Channel: SkillSharp
Views: 170
Rating: undefined out of 5
Keywords: Python, virtual environment, virtualenv, project dependencies, package management, Python development, tutorial, Python packages, virtual environment tutorial, Python project management, Python version control, isolated coding environment, Python development best practices, clean coding, software development, programming, coding, Python programming, software engineering, SkillSharp
Id: 0AU8a8qQyhw
Channel Id: undefined
Length: 8min 43sec (523 seconds)
Published: Sun Jul 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.