Set Up Python Virtual Environment In Visual Studio Code (VS Code) | VSCode activate venv

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I am going to show you how you can install and use numpy with your Visual Studio code editor so let's get started and let's see how can we can do it so go to the folder where you want to create your numpy project so just open it in your folder Explorer let's say I want to create my numpy project here so I can right click here and then click on show more options and click on open with code which is going to open this folder in Visual Studio code editor you can see python apps now here you can create your numpy app for example I am going to name my file as num underscore test dot py file okay and it has created my python script here I'm going to add a very simple numpy code and save it now in order to ah install numpy in your Visual Studio code environment you can just click on Terminal and then open a new terminal here and once the terminal is open you can choose between Powershell or command prompt here so let me choose the command prompt option from here okay so you can see the command prompt is open so you can switch between terminals from this terminal window so I'm in the command prompt window and what I'm going to do here is I'm going to create a virtual environment for my project so to create a virtual environment I can just write python space hyphen M and then VN v e n v and the name of your environment I can name my environment as my n or something else the name depends on you so you can give any name to your environment just press enter here which is going to create this my and folder okay and you can see it says we noticed a new environment has been created do you want to select it for the workspace folder just click on yes here and once you click on yes Visual Studio code is going to recognize your virtual environment and then it's going to show you some options right now when you go inside this virtual and folder you can see few scripts here and there will be a script called activate so we want to uh use this activate file in order to activate our virtual environment so in order to do that you just need to write this command so just write whatever is the name of your virtual and folder in my case it's named my n and then give forward slash this is a forward slash and not a backslash right then write scripts forward slash activate you can also write forward slash activate dot bat file because you can see under script you have both this file activate and activate dot bat let's run this with without dot bat I'm going to press enter and your environment has been activated and how you know that your environment is activated you will be able to see this my n under these parentheses before this Command right so once you see your environment before this folder path that means your environment has been activated right now in this environment you can just install any package and this will be applicable only for your environment for this project okay so here you can just type pip install numpy and then press enter which is going to start installing numpy package in your virtual environment for your project so you can see it says installing collected package and once a numpy is installed you can see this message which says successfully installed numpy and the version of numpy you might see some warnings here you can see you are using Pip this version and the newest version is this one so just try running this command you can do that there is no harm in doing this so if you want you can run this command so you just need to run this command in order to upgrade your pip package manager so you can just write pip install then upgrade before that you just need to write hyphen hyphen upgrade pip okay and then press enter and it's going to upgrade the PIP okay so let me just run this numpy script we have created a virtual environment we have installed numpy package so the only thing which remains is the running of this file so you can run this file by just using the python command so just write Python and then the name of the file which is num underscore test.py and then press enter and it will show you this result if it shows the result of your code that means numpy is installed in your Visual Studio code with virtual environment and it's running fine right you can also install the extension which is called code Runner so just click on extensions and then search for code Runner which is a very popular extension for running various kind of codes so just click on install option here I have already installed this extension that's why it shows me uninstall but in your case you will see install option so just click on install and you will see disable or uninstall option once that is installed you will be able to see this run button on top right corner so the code Runner adds this button on type top right corner so just click on run button and it's going to run your code now when you run your python script with this code Runner you can see this error which says no module name numpy is found to solve this problem you can just add this line at the top of your code so let me show you uh this line which you can add at the top so just write hash and then this bank and then go inside your virtual end folder then go inside your script folder and then click on python.exe file right click and copy the path so just copy the path here and then just paste it after this hash bang okay so hash bang and then space and the path of your python exe in your virtual end save your code and run this code once again and this time your code will run okay so this is how you can install numpy on Visual Studio code to work with numpy inside your Visual Studio code I hope you enjoyed this video and I will see you in the next video
Info
Channel: ProgrammingKnowledge
Views: 58,085
Rating: undefined out of 5
Keywords: how to activate virtual environment in visual studio code terminal, activate virtual environment python, vscode not detecting virtualenv, how to activate conda environment in vs code, python: select interpreter not found, how to select interpreter in visual studio code, visual studio code environment variables, vscode env file
Id: yG9kmBQAtW4
Channel Id: undefined
Length: 8min 26sec (506 seconds)
Published: Fri Apr 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.