Learn Python 3: Visual Studio Code for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello this is Joe Neville welcome to another Python video and in this video we are going to look at installing Visual Studio code if you don't know Visual Studio code or vs code for short is an editor which helps you to write code and many other things now this video series is focused on Python and vs code is multi-language so you can write Java you can write C etc and you can write Python but what it means is that there is some tweaking that you need to do to set up your Python environment and that's what we're going to show here so let's jump into it then here's my Windows 10 VM which I used in my first video if you haven't checked that out then please do I was looking at virtual environments which is particularly important for this video as well for getting your environment set up I've installed Python 3.7 and I've installed virtual environment wrapper but that's it let's install vs code then open up edge do a search for visual studio code and we have this green box here download for Windows run that ok then we have this License Agreement pop-up list minimize that to focus on this here so we've got the license agreement of course read all of this then accept the agreement next I'm just going for the default directory install yes these are some useful options here create a desktop icon add open with code action to your Windows Explorer file context menu yes I'm going to select those and register code as an editor for supported file type so I'm going to select all of those hit next then I am going to go for an install you okay that's now installed completing the vs code setup wizard launch vs code okay hit finish there and that will open up the agency we've got a desktop icon camouflaged against the blue of the default background and what happens here is we have the getting started webpage is automatically fired up which gives you a lot of information about how to set up the environment but what I find with this is that when you start out it's a bit like information overload so there's so many options and partly because as you can see down here you've got so many different languages that vs code is very popular to use to write so you've got no js' you've got PI from there Java C++ etc etc we just want to focus specifically on how to set up a Python environment I'm going to close that down close all of those down fine and let's just focus on Visual Studio code now this is the welcome page okay and again I think it's a bit of information overload so what you have down here is you'll see pop-ups and I was having a conversation with someone on Twitter and they were saying that the popups were annoying them that's essentially why I'm making this video is because that was my experience when I first started with Visual Studio code I saw all of this information it's all trying to be very helpful but it was kind of overwhelming with what do I need to do to just get my Python environment set up so this is for telemetry I'm not particularly concerned about that but if you are do look at the opt-out options there I'm just gonna close that down so that's your first pop-up so back to the Welcome page then I'm going to turn this off so the Welcome page doesn't start up because if you don't turn that off then every time you log into visuals code you get your welcome page now there's lots of useful things on here so you can do things like new file open a folder etc then there's great stuff like the principal keyboard cheat sheet which is worth clicking onto to have a look at that and over here you've got tools about setting up your different environments some SETI's color theme etc etc but the thing about this is that this isn't the standard process that you would use so I don't think that this is particularly useful for you to actually learn the settings and the the workflows that you're use with Visual Studio code so I'm not gonna go through this even though it does lend your lend you a helping hand with installing Python we're going to do that setup manually so I'm just going to close that down because in the long run I think that's better now it comes with this attractive dark theme but for my video I'm going to use light theme because I know for some people that that works better especially with presentations etc I tend to write in the dark theme but I do all my presentations in a light theme so to change the color theme go down to this cog here which is the manage button ah before I start actually what I'll do is I'll make this bigger so let's do a ctrl + let's get that nice and big for you okay fine so what back to changing the color theme hit the COG down here and you see that this is actually your route in to lots of different settings so you've got your command palette you've your settings you've got extensions which we'll go into in the moment and down here we have color theme also I should say check for updates so there's a monthly update to vs code that's the cadence that they've been using you'll see a number against this if there is an update and you hit the COG to install the update so we've got a fresh version there's no update but this is where you would go to check changing the color theme then so hit that and we see these are all the default color themes and if you do our pero you'll see you get a preview of these you get ones like this red so a dark very attractive and at the bottom there you can install additional ones like community focus ones now what I said I was going to do is I'll go to light so I'm gonna go for this light plus here it's a light and light plus light plus just gives you a bit more contrast with the colors in your code fine okay so light plus then we have this toolbar along the top but what will the main way that you interact with Visual Studio code that I found is via this activity bar down on the left so if we go through these what you have is the Explorer so just like on Windows with the file explorer to allow you to open folders and create files etc if you hit that it will it expand if you hit it again it will disappear to give you some more real estate on your screen moving down we've got the search function so you can do find and replace by the looks of things you can do so source control this is if you are using git which of obviously you should I'm not going to cover that in this video but when you create a folder that's covered by get you can use Visual Studio code as like a geek GUI so you can do things like push and pause things like that actually just within vs code which is fine but I we've geared I recommend that people learn the command line because that's how you really learn what's going on with get rather than using gooeys next one down is debug so a bit more advanced than your basic setup but it's a great function to have within vs code possibly do more on that in a later video and then finally this is extension so you're going to go here pretty early on like I said this code is multi language so what we need to do is for the language that we want to focus on to use our editor we need to install the extension so you have some extension see if we hit that it's giving us the most popular extensions there so as you can see there's over 12,000 extensions some are published by Microsoft some are more community based we're gonna go for oh in the word the way that you search is just by ty being there so if we were to type for example if we wanted to write some go we could get the go language support and you hit that button to install it but of also there's things like if you're looking for markdown is another one that I use but of course we are going for and it's the most popular one Python so this is published by Microsoft let's install that extension so that gives us additional Python functionality and you get lots of information about that here I'm just gonna close that down for now so we've got that installed another nice one to just make things look a bit prettier is the vs code icons I like to install this as well so vs code - icons install that okay well activate those you get this option here if the those are the default so I'm going to go for the vs code icons good stuff right let's close that down and get rid of extensions and let's write some code then so we'll go back to Explorer and we want to open a folder now I'll show you how I've got my folder structure set up in Windows if I go to so what is it see users Joe and I usually use a code folder we're going there we've got my cool project okay so let's let's open that up so the way that we do that going on open folder it's the same again my cool project okay so select that now we have that open within vs code you can see the name of the folder across the top and here we have the folder and we can create folders in there or we can create a new file so let's hit new file and we'll go for of course a hello world and vs code picks up what type of file it is by the extension so if I was to type go you see the icon change there if I type py we know it is a Python file and then we get the two snakes next to us okay so here we are hello world and what you'll see here is because we've created a Python file it will be looking for vs code we'll be looking for a Python interpreter and here come the popups okay so this is the thing that I think is a bit confusing for people now the first one is about the linker that's not installed so we've got lint a pilot not installed that's moved okay so linting is essentially like code spell check so it's great to have a linter and there's different types that will check your code and make sure that you have written it to certain standards now I'm not going to look at that in a moment we could delay that for the moment let's close that down right let's look at the interpreter then so the interpreter is our version of python that we've got installed on windows and that's down here on the bottom left if we hit that it will bring up the interpreter there so this is if we've got multiple interpreters this is where we can choose them so if you add python to installed it would appear up here and you could choose between them for this Python environment now if you checked out my first couple of videos I was talking about the importance of using virtual environments so that you're not just installing all of your packages on to the global install of Python so for our new project I would recommend that we use a virtual environment to keep everything nice and compartmentalize to keep it nice and tidy now how do we create the interpreter and get it linked in to vs code we could jump out of this code and use a terminal but what I'm going to do is use the built-in terminal great thing about this is if you're working off a single screen like if you're using a laptop for example you can just use vs code maximized and you can get access to lots of the tools that you'll need for your development environment including a built in terminal so for the eagle-eyed you'll see up the top here we've got terminals so I can open that and you've got the shortcut therefore it's a new terminal let's open that up here so it's a standard powershell so if you want to enter commands like it you don't have to just do code commands if you do like an IP config etc et-cetera you can do SSH or for this so so I can just see in vs code and I can configure my switch II okay just clear that off now what I'm going to do then I'm going to create a virtual environment manually so that's Python - M VM and I'm gonna call it hello world let's create that and down here you'll see we noticed a new virtual environment has been created do you want to select it for the workspace folder so I'm going to say no at this point because I want to do it manually but you can see that the functionality is ravine vs code to be able to pick up your virtual environments like that now let's do this manually then so we want to select the virtual environment if I hit that bottom left you'll see at the top here there's my hello world virtual environment so I can select the global or I can select the hello world let's select that and you'll also see over here in my project there's the actual folder with the binary set cetera for hello world okay we've got that linting warning again and it's telling us pilot is not installed now I'm not going to use PI lint I'm going to use peppe's now that's not going to be installed either so the message the pop-up changes link toph f8 is not installed if we hit this it will go and install it for us now what I have noticed is that you get this warning but that's because PowerShell can't run scripts on this Windows VM by default but what it does is it just takes a different approach to install it and it is successfully installed here into my environment so now I've got my linter installed let's close this down clear this off sorry and I will minimize that let's give ourselves some more real estate then by getting rid of that and I will let's do a simple program so do message equals hello world and I'll go print message okay now you may have noticed that there's a dot up here now that and also a one over here and what that means is that this file is not saved at the moment autosave is not on by default with vs code to change that go to file and they go autosave so we hit that and if I make any changes to the document you'll see that you don't get the dot you don't get the one because this is automatically being saved which is really useful let's go ahead and run my simple hello world program then and you don't need to drop out of vs code you don't need to use the terminal for this you can do a right-click and if you look down here you can see run Python file in terminal the other one is run selection line in Python terminal so this runs your whole Python file and this one if you highlight and right-click it's the selection that will be run so if you want to run just a selection of the screen or if you want to run the full file so let's run the whole file here and oh it runs we've in the virtual environment that we've got the hello world virtual environment and then it's printed to screen like that let's bring this up a little bit for you okay so if we look at it over here you can see that there's a problem and one of the problems is blank line at the end of the file because this is our linter telling us that we're non-compliant with one of the rules of the pipe eight linty we can also change it by doing things like this will give us some errors as well so that you can see we've got two problems and it tells us what the problem is missing white space around operator the operator being the equal sign there if we high like that it will actually tell us where the problem is so this is really useful if you've got a large program and then you've got different problems you can highlight them and it will show you where the problems in your code are these are just formatting problems so the file will still run if we there we go if we change that if we run that we still get hello world but this is formatting and limiting which is telling us we need to change that so if we go let's get rid of these problems then and also the blank like you see I've put the space around the operator now the problem has disappeared and if I do so it's blank line at the end of the file if I press ENTER there then now we've got no problems so that's great it's nice and clean and we're compliant with PFA run that in the terminal fine you'll notice that I ran that manually and that can be if you've got lots of issues like this it can be quite time-consuming to actually go through and manually change them so there's a tool that you can use there's formatting tools that you can use to automatically do that for you and you can link those into vs Co so vs code will run the formatter for you now how we do that is we can go we need to open up the command palette if we come down here and open up the command palette and I write format you'll see format document so that's not Python specific but it will pick it up that we want a formatter for Python and we've got this option here so formatted auto Pepe it's not installed you want to install it now another really popular it's quite recent and very popular formatter is black so lots of people are using black and now that's what I'm going to use here so I'm going to hit the use black box okay and that goes off and it downloads and installs black 4 so you can see we're making these shortcuts we didn't even have to go and find black to install it vs code goes and does that for us now what we want to do is we want to black against this file here now if I right-click you can see for map document you've got format document with or you can just run format document so we've run that and as you can see it put the spaces around the operator it's taken out the blank line and our problems have gone if I quickly just do that again for you are and add the I take away the white space again format document and the problems disappear okay great so that's the power of using linting to tell you where the problems are and then you can use a formatter to actually automatically make those changes for you make your code easier to read now another option is if we want to have let's create another file so we hit that and we'll go hello to dot py and imagine I want to work side by side or close down the editor then imagine if I want both of my files on screen at once what I can do is we go over to the top right here split editor right and that will split that across I can close that version down and then I have hello world here and hello world two over here so I can do things like copy this across copy that across okay hello world - and then so if I put my cursor in hello world stop I right-click will get hello world and if I do over on the right there Ron - file in terminal I get hello world - you're gonna have multiple of these so you can split that out and have three or four etc okay let's close that down now I did show you the command palette there the command palette has a huge amount of actions that you can run if you want the Python specific ones just type Python and those who will come up there so it has things like run the Python file in terminal now we can get to that via the right-click as I've shown you or you can use the command pilot so right clicks obviously quicker selecting the interpreter and things like that so if I connect that that will bring that back up rather than there's multiple routes to do the same action the other thing that we have available here is settings so this is different because this is the actual settings are closed down the term of this so you can see this then you have this GUI for the settings so we have commonly used like autosave I've got autosave on after delay you can change that to off which is the default and it tells you there you've got the default on focus change on window change etc you can change the font size this is where all of the settings are now if you go to yeah if we go to extensions if you want the python specific ones you can go into python here and you'll get - specific settings i'm not going to cover any more of those in this video for now - let's close that down and the final thing that i'd like to show you which did confuse me to start with but it's actually pretty easy pretty easy and really useful art workspaces so imagine you have multiple projects on your computer and you'd like to have a look at some polyfill code or another file that's in a different folder you could go to file open folder and I've created this second projects a project to imagine this and Python in there that we want to look at side by side so if we select that what does the s code do well actually completely flips the folder to project two and in project - I've got hello - and I've got a dot py file of hello - and you see the popups are popping up again because we don't have the same interpreter linked to this folder so that's not exactly what I was looking for and you could say okay well bow for these folders are within the code folder so we can just use the hierarchy to our advantage we could open folder go up one level to code select that and that will have both for the project so if we bring up HelloWorld we can split that across we could also have hello - in a completely separate folder alongside so we could compare those and run them separately but what if your projects and your files are in a completely different part of your OS not in the same hierarchy how would you get to those well that's where workspaces come in so let's go back to our original we'll go open folder and I will go back to my cool project and I've got a different folder I'll show you in the file explorer where it is if I go see users I put it in public so it's not in the same place document so it my other project that's the folder that I want to open okay so how do we do that we could select in the folder we'll just flip between what we do is we go to file and we go add a folder to workspace so select that and we go find that again documents so this is the folder that we're going to add into the workspace and then rather than flipping the folders we stay on HelloWorld in Michel project we also bring in this new folder and we create an untitled workspace so we're now free to create Python files in a completely separate folder but in the same workspace eh you'll get these pop-ups again because it doesn't have the interpreter you can select the interpreter there and we can split that across so we can have Python files in completely separate folders side by side in the same workspace and let's run there we go great so we've got our hello world three and if you want to link those folders together in the workspace if we go over to file and we do save workspace as we call it my work space one save that if we were to entirely close this down to closed workspace and maybe we shut down we boots up the next day and we want to start the game where we left off we can up now open a work where you can go to open Rison and that will bring the works but there you can see workspace we can just go open workspace and it was in my other project so there we are that will open up the workspace for us and if you want to remove the folder from the workspace we can just go there remove folder from workspace and we're back to just my cool project so I did find that very useful when you've got quite a lot when you've got multiple projects on your OS in different areas allowing you to bring them so that and the main driver being that everything can be done single screen so multiple folders terminal you can also run as I said like you get debug etc et-cetera all on the same screen all on a single laptop screen oh and before I forget the actual real honest-to-goodness final thing that I'm going to show you is if you're using virtual environment wrapper can vs code pick those virtual environments up remember from my first video those virtual environments are consolidated rather than sitting in the actual project they're in a centralized place wellyes vs code can pick those up so let's create a new one I'll open up a terminal right and we go make virtual em and I'll call it V hello fire that off and once that's done if we click down here vs code won't pick it up but if you close off I found if you exit out of es code then open it up again so we're back in our michael project it loads the extensions if we select there there you can see it has picked up the environment on a different path so we can now select V hello we have in vs code so it's another nice thing about vs code that it has got this built-in functionality which also picks up so what do we see we saw it picked up formatting with black you've got pep 8 you've got awareness of virtual environment wrapper centralized virtual environments so it's a really good really powerful tool when you're writing your Python code hope you found that useful then so that was a whistle-stop tour through the first 5 to 10 minutes of setting up vs code for python please like subscribe comment if you need any extra pointers on this please do let me know always looking for feedback good and bad but that's all for now thanks very much for watching my name is Joe Neville and goodbye [Music]
Info
Channel: Airheads Broadcasting
Views: 69,680
Rating: undefined out of 5
Keywords: python, coding, visual studio code, windows
Id: RdD47NPku30
Channel Id: undefined
Length: 30min 55sec (1855 seconds)
Published: Wed Jul 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.