Using Python with Anaconda and Visual Studio Code (Windows)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my video about how to set up anaconda in Visual Studio code has been very popular but I made some mistakes in it and the procedure isn't working for some people and so I created this update to hopefully alleviate some of the problems you've been having I hope you find this useful and if you continue to have problems please let me know and I will try to address those so once again hope you find this useful and you can check out open source options com for more courses and tutorials in this video I'm going to show you how you can link up your anaconda environments and your anaconda Python interpreter in Visual Studio code on windows so first make sure you have anaconda installed anaconda installed and make sure you have Visual Studio code installed I'm not going to go over the installation in this video there are lots of videos online that you could use to to install those if you don't have them installed already okay I'm also going to assume that you use the current anaconda default in recommended settings for installation and when you do that they recommend you don't add anaconda to your path variable or to your Python path so that you're compatible with other users on your systems so I'm gonna make those two assumptions I'm dependent if you installed this differently I'm gonna do it you just recommended settings then you may have some issues with the video that I'm showing you here the steps have a showing you here so be aware of that the first thing we want to do is we're gonna open up our File Explorer and I'm going to go to where my anaconda installation is so for most of you it's probably on the C Drive users your username anaconda flea okay that's kind of a default location as C Drive users your username so I'm gonna go here to an economy and I'm gonna click on the top bar here the path bar and I'm just gonna copy that you can do control C or right-click copy like that okay so once I have that I need to add this path and the path to the scripts folder to my environment variables for my account and the way we do that is we're going to open up our menu here and I'm just gonna start typing environment variables and I'm gonna go to edit the environment variables for your account okay and I want to go back and do this one more time for you select click environment variables you might click on edit the system environment variables and if you do that is gonna bring up this window you can get someone to I was just at by clicking on environment variables and it gives you options to edit them for your sister for the system or for your account I recommend you do this for your account you're gonna be able to have had this fully functioning for your account if you do this if you use multiple accounts for one but if those for multiple users then you can do with the system variables so here we want to click on path we want to click Edit ok you can see I already have these added I'm just gonna go ahead and delete that one and delete that one ok and so you can see here this is what yours will look like something like that you won't have the Anaconda past on this so now I'm going to click new and it gives me a new line you can right click and paste or you can do ctrl V and then I want to click new again and I want to do console B to paste that in there backslash and type in scripts so also links to the scripts folder and now I have those two on there once I have those you want to make sure you click OK and click OK again alright so now my environment variables are updated click OK here now I'm going to go and open up visual studio code let's go start by visual studio code and let's go open that up ok now let's go ahead and open a folder and we'll create a new folder to you just put a Python file in and make sure that our anaconda installation works I'm here in downloads I'm going to make a new folder called PI test and I'm going to select that folder okay so now we have that open now before you do this if you haven't done this already you're going to want to make sure you've been able to installed this python extension so your extension spiders right - extensions and you can type in Python now it's this one right here it's just the general python extension and you're going to just want to make sure you install that in order to continue here I'll go back over to my window so once you have that installed you'll be good to go I'm going to go back over to my Explorer and I'm gonna go to my PI test folder everything add a file and I'm gonna call this test py you can see I automatically recognize that it's a Python file and if you notice down here it's loading a PI it's loading the Python extension it found my con debase environment already Python three point seven point four and I found that because I put this in the path variable now let's try to import numpy numpy and just run something so new import numpy as an p sorry as NP I don't like this autocomplete I don't know why I wants to do this anyway I'm gonna fix this is bugging me okay important on PE numpy is NP and we're just going to make a variable called a equals NP a range 10 I don't want to print a okay and this says Python is not installed money to download and install Python before using the extension we should be okay here and we might have to troubleshoot something let's go ahead and give this a try so we have this code here let's do ctrl s to save it and let's go and click run see what happens okay so you can see that we've gone and we've done Conda activate base we've activated our base environment and then we've printed out our array that goes from zero tonight okay so our code worked now let's say that I want to change the environment I'm using okay and I have other Conda environments in my base environment say I want to use a different environment well it's actually really easy to do if I do ctrl + Shift + P ctrl shift P will bring up this palette bar and you can type in select interpreter okay and when you do that I'll give you a list of options here doing Python select interpreter it will bring up a list of the available interpreters you have so you can see here that I have two different Conda environments there in my anaconda 3e and Vees folder and I have this pi 37 Conda environment let's go ahead and click on PI 37 and let's go ahead and click run and see what happens here let's go click run okay and so you can see that here oh we had the exact same thing happened it didn't actually go run that environment to activate in my base environment again let's see if I can quickly run here real quick and see if it works this time so we're on base click run and it's still only activated base let's try to type so one thing you have to do here to you let's go over this real quick most right here if I click this I can select my default shell and it's going to give you different shell options I would recommend you select command prompt okay so select command prompt and at this point we might need to restart visual you might need to restart visual studio code okay if you get errors and this is not running fooling you that would be the first thing I suggest you do is go to select default shell again select command prompt and then restart visual studio one way you can check to make sure things are going to work you go to your windows type in CMD and bring up your command prompt and here if you type Conda you should get this helpless for Conda okay and then what you can do is you should be able to type Conda activate bass oh and I spelled it wrong so Conda activate bass and you see we got an error here we should be able to activate this from our shell so let's type let's just type activate bass and that works so the newer version of Conda we just need to use activate bass and you can see we're now using the bass environment sorry let me zoom in on that for you we're now using the bass environment okay and if you can do this in your command prompt it should work in Visual Studio code now we could type deactivate and you can see that it no longer says base here and now let's type activate PI 37 and you can see we have PI 37 activated there and if we type Python this will tell us our python version right there right so I'm gonna get that quit to exit out of Python okay so things are the working in our command prompt I'm just gonna deactivate this okay if these are working they're come over to Visual Studio code you can type deactivate here and you should see bass go away and it does and we should be able to click activate pi 37 and we do that and we get PI 37 there and it works and so we're good to go so you can see well using our PI 37 Konda and so and one thing I failed to mention is that even though it might say bass down here if it says PI 37 here that's what the code is running it might be printing this out saying it's using our base interpreter here but it's really using this interpreter by the Python code so let's just type deactivate I'm going to type deactivate here so that I'm not using any interpreter let's go ahead and click a run and see if this runs again okay alright so now we have a problem it can't find anything because we've deactivated the environment so let's come down here and let's click activate let's type activate PI 3 7 hit enter and now we have our PI 37 environment activated here and here and now let's click run and you can see that our code runs ok so this is how it might be a little confusing a Visual Studio code because we have our terminal here where we run Python code and we have our code here that we're essentially running from the terminal but you can see that I've successfully hooked up my environments I can activate both environments I can activate an environment here in the terminal I can also use control shift P and type in select Python interpreter let's look until today and I've had an interpreter and I can select my different interpreters here to be able to do that okay so just make sure that activate base that you're switching here to be able to have the same interpreter or your same environment here that you're running with here in Visual Studio code and once you do that you're able to use all your different economy environments and how whatever environment you have whatever projects you can use those in Visual Studio code so I hope this video is helpful please go check out open source options comm for more information for more tutorials on data science and GIS and you can see courses I have there that provide a lot of value with code and with data they can help you get started with data science and GIS if you have questions thanks for watching guys hope you have a great day
Info
Channel: Open Source Options
Views: 108,376
Rating: undefined out of 5
Keywords: open source, open source options, open source software, free software, visual studio code python, visual studio code anaconda, visual studio code python environment, visual studio code anaconda envrionment, python envrionment, anaconda environment, visual studio code, windows, visual stdio code windows, python windows, anaconda windows
Id: 3Wt00qGlh3s
Channel Id: undefined
Length: 14min 9sec (849 seconds)
Published: Tue May 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.