How To Setup A Virtual Environment For Python In Visual Studio Code In 2023

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm going to be showing you how you can create a virtual environment in Visual Studio code so that you can install packages such as Discord or telegram or pandas in your python projects so the very first thing we're going to do is create a new folder somewhere on our computer and I'm going to name this folder and this is the folder that's going to contain our python project and once you have that folder you can just drag it into Visual Studio code and inside here we're going to tap on new file and create main.pi and click on create file so we can type in our python code now in this example I'm using python 3.11 which I've already installed and in case you don't have a python interpreter selected go down here and select the python interpreter that you want to use at the moment if you were to type in something such as prints hello and you were to save and run this it's going to print hello in the console but what if we want to use some functionality from an external package such as from Discord usually in a lot of tutorials you're going to notice that they're going to type in PIP install Discord but in Visual Studio code we're going to get this error that the command was not found and it's going to say pip so why is that the reason behind this is that we're trying to install it in a place that does not make sense pip cannot be found in the place we're trying to install this we're just in a normal folder that knows nothing about pip and this is not where you manage your packages so what we need to do is first clear everything from here so we can have a nice clean terminal and next we're going to use a command to create a virtual environment and this is going to be different between Mac and windows so on Mac you're going to want to type in Python 3 on Windows you just want to type in Python but here we're going to type in Python 3 because I'm on Mac then we're going to use Dash M vnv.vnv and then tap on enter and it's going to create a new virtual environment for us and you're also going to get this pop-up message down here that says do you want to use the new environment for your workspace folder and we're going to click on yes and it's going to change python 3.11 to python 3.11 virtual environment in case you missed that message and you're still on python 3.11 you can just tap on this and change it to the virtual environment now does that mean we can type in tip install Discord now and the answer is no as you might have noticed we're still in the same folder we're not in the virtual environment just yet even though we've selected it down here we need to kill this terminal and we need to start a new one just by running the script again and this time you should notice that just by running it with the virtual environment it's going to activate it and it's going to put us inside that virtual environment so right now it says dot VNV and then it has our folder name and I'm going to clear this once again so that you can see that at this point we can finally install packages because we are inside the virtual environment so if we type in something such as pip install Discord it's finally going to install it using pip and inside the virtual environment folder there's a library folder and you can actually verify that you've installed it so here we have Discord inside the folder and because of that we can also just import Discord and we can use everything from the Discord package so now that we have a virtual environment you can install any package you want and that's actually all it took to create a virtual environment in Visual Studio code so with all that being said thanks for watching and I'll see you in the next video
Info
Channel: Indently
Views: 196,961
Rating: undefined out of 5
Keywords: pyton, pyhton, pythn
Id: GZbeL5AcTgw
Channel Id: undefined
Length: 4min 0sec (240 seconds)
Published: Fri Apr 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.