Getting Started With Python Virtual Environment In VS Code For Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey house and guys in this tutorial you'll learn how to work with python filter environments in Visual Studio code so I'll cover the basics of water python virtual environment is why it is useful and how to create and use a python virtual environment in Visual Studio code so it's a reference I'll be seeing vs code instead of Visual Studio code are going forward alright so first let's define what the python filter environment is a python feature environment is an isolated environment that allows you to install python packages and dependencies for subsidy project this means that you can have different projects with different packages installed independently without fighting other projects dependencies other benefits such as virtual environments make it easier to show your code with others because you can create a requirement text file that lists all the dependencies for the project python virtual environments also keep your projects organized and it takes less than 30 seconds to create a python virtual environment Now to create python virtual environment first you want to open your terminal and I'll be using bash as my default terminal you can also use other terminal such as command line tool or Powershell and this will work too so many people think you can only have one python future environment Creator and that is simply not to you can create as many python virtual environments as you want as long as your PC has enough storage so for example I host all my python virtual environments you can sync those as my python projects now if you look at uh this photo right here I named the directory python VMV stands for python virtual environment now if I simply select all my project folders so in this directory I basically have 28 projects created now going back to my terminal and to create a python virtual environment I'm going to type python Dash m so Dash m stands for module basically you want to specify the module that you want to use and here I'm going to type BMV which is going to be the module name that we're going to use to create a python virtual environment followed by the positioning or the environment name in this for the environment name I'm going to name the environment my project enter now going back to my python VMV to actually I should see a new folder got created now double click to go into the folder and on my terminal I'm going to set it into the directory as well it's going to be my project now before you can use the environment you need to activate the environment first and which is very important step and to activate the environment inside the environment folder you should see uh three folders in one file inside Pi bmv.config file help me open the file so you can uh check it out so let me open the file with my notepad so basically uh what is a pi pmv.config file doses the python filter environment is going to create three variables that are pointing to the default python interpreter that is going to use to run the python code in these two properties are not very important so I'm going to skip those and just in case if you upgrade your python version then you can update the file path pointing to the updated python interpreter now to activate the environment inside the scripts folder want to run this an activate file if I was in Powershell then you will need to run this will activate.bat file now going back to my terminal I'm going to type Source because I'm using a bash if I was in Powershell or command line tool you can simply run the file directly so here I'm going to type the file path to the activate file and press enter now you know your environment is active by looking at the environment on top of the prompt now at this point everything you do is only going to impact this environment only now let's learn how to use Python virtual environment in VSCO so here let me go back to the root folder and I'm going to launch my vehicle alright so please uh to Windows side by side now the first you want to do here is you want to create new python file so I'm going to use the shortcut Ctrl n to create a new file so in my vehicle my default environment is set to this gcloud environment and to activate a python Fusion environment in VSCO I first want to launch the command palette by using the shortcut Ctrl shift p they want to search for python select interpreter and that lists are all the recently used python fireman projects now just in case assuming that your project is not loose decent list right here so what you want to do is you want to click on this uh enter interpreter path and we're going to mainly select the python virtual environment interpreter all right so here are the default directory so it is set to my partial folder so I'm going to go into help me make the icon look bigger so I'm going to go into the scripts folder they want to select the this python.exe file and this is the python interpreter that is being used by the environment now select The Interpreter now if you look at the start spot in VSCO and you should see the item environment is updated the iPhone 2 deactivate the environment you can simply type the after there and finally we felt down with the environment you can simply archive the folder to your hard drive or you can simply delete the folder if you don't need the environment anymore so once I forgot to cover was so let me go to the vehicle settings window first all right so we can click on this gear icon then click on settings now in the search bar you want to search for python VMV and that's going to list all the configurations that's related to python virtual environment and as I mentioned before we can have as many python feature environment as we want but once I forgot to mention was the old environments are ideal are in the same home directory under this python VMP photos property we can set the home directory where all your python environments are host so ideally these two photos should be the same and if you have multiple python version buyers you want to use from the environment as the default environment every time we launch vs code in your random directory it doesn't necessarily need to be a first environment folder it can be any folder and VSCO is going to use this interpreter as the default environment so there's going to be everything I'm going to share in this video and hopefully you guys find this news for and if you enjoyed this video please don't forget to give this video a like and click on the Subscribe button and I'll see you guys next time bye
Info
Channel: Jie Jenn
Views: 7,968
Rating: undefined out of 5
Keywords: vs code, python tutorial, python virtual environments, venv, Virtual environment, VS Code
Id: q1ulfoHkNtQ
Channel Id: undefined
Length: 7min 42sec (462 seconds)
Published: Wed Mar 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.