Setting up VS Code for Python Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right april so we're going to do some python today yes yes we are doing python and specifically for those of you who um if you have python experience great if not it's okay this is a nice introduction to where you can go and place your code and that's going to be inside visual studio code rock and roll let's do it all right so let's get started everyone here on the screen i have the visual studio code website so you can find the visual studio code download as well as a documentation by visiting code.visualstudio.com the home page has a handy download button however if you want to explore versions for other platforms you can always select download in the top right and then you'll have for windows as well as linux and mac once you have that downloaded you are set and ready to start coding in visual studio code so i'm going to give you a quick little tour of what's happening in here before we head into some python just in case it's your first time seeing the editor so starting out with this far left area to the far left that's going to be the activity bar that activity bar has various icons in there and those icons all represent different views that are available if i were to select a view it'll show here to the right which is going to be the sidebar and so depending on which one i select right now i'm an explorer i can see all the files within the folder that i happen to have open if i were to navigate let's say to run a debug then i would be able to see what's happening with the debugger here in the middle is where i actually have the editor itself where you can actually go and edit files you can have multiple um uh let me see windows open if you will for the editor and you can group them together as well very convenient for those of you who do want to keep things a bit more organized in vs code and then down below just below the editor i have panels i can move these around down here is commonly where you're going to find the terminal as well and you can have multiple terminals and we'll do some work in the terminal here in just a bit then at the very bottom this blue bar is where i have the status bar so at that bar is where you're going to have different information with regards to the files that you may have open and also if you happen to have any extensions installed and we'll talk about the extensions in just a bit you may have some additional activity that's happening down there as well so that's a quick uh guide around what visual studio code uh looks like in terms of the interface so you do have some options in terms of customizations that you can add if you will to the editor and so whether you want to move around different panels whether you want to change the color themes for example right now i'm in dark mode however there are a variety of themes available especially from the community that have contributed them as well so you can always add that to the editor just to jazz things up a bit but as for the python piece let's head into the extension uh marketplace so the extension marketplace is where you're going to be able to find additional let's call it features that you can add to the editor to really enhance your experience so within here is where you'll be able to find the python extension and the python extension is what's going to provide additional support and functionality for programming in python and visual studio code so microsoft has their own python extension within the extension view if you search for python it will pull this down it'll show more information about the extension itself there's some documentation that might be helpful for you but most important what we'll want to do here at the top is install it i happen to already have it installed so if you don't have it installed it'll be an install button right around uh below the title where you can select that and it'll do the install okay so that is the extension now the extension itself like all extensions also have some settings that you can change to make things more suitable for your needs so if you're brand new to python this might not be something that's going to be as impactful but if you have been using python for a while and you're familiar with concepts such as formatters for example or linters that's where the settings will come in handy what i recommend is that if this is your very first time using the python extension in visual studio code program first and then once you're comfortable that's when i would say go in and make those changes but if you're curious as to where that is if you go to file preferences and then settings there's an entire section on extensions you can also search for python at the top and then within the python section this is where you can find different settings so the default interpreter for example which we'll touch upon in just a second as well as i mentioned formatters and linters as well so now that we have the python extension we're just about ready to look at some code but i did mention interpreters so what you're going to need to have is an interpreter selected in visual studio code to start doing some programming with python i happen to be using python 3.8.5 at the moment but that's not the one that i have to use for the interpreter if you don't have one selected in the bottom left corner of the um of the of the screen you're going to have a option to select an interpreter if you see that then click it or if my case i already have one selected by selecting that i didn't have the opportunity to select an interpreter i can also define the interpreter's path as well if i have it somewhere else on my computer so you can select that also while we're in here you can also as a heads-up you can also have virtual environments as well as conda environments if you happen to have either or that's also going to show up here in the interpreter too so there's another way you can also access the interpreter and it's probably one thing that i love about um vs code is that there's so many ways to do the same thing which is great it's just a matter of what's your personal preference but with that said you can use the command palette that'll be ctrl shift p there's a lot happening here in the command pilot and it provides another way to get to something or access something or execute a command with the shortcuts so outside of the interpreter option as i have here that's something recently used with regards to the python extension if you type in python in there there is just um a wealth of other commands available um too so that's just a little quick tip with regards to the command pilot so april when you say the interpreter that's just a python installation right it's always been confusing for me is that it's called an interpreter but it's just python right yep that's what it's going to be and um i know in the past i've had like another version installed and so if you happen to have multiple versions installed for whatever your project needs seem to be you can also select a different one but for me right now i just have 3.8 and on my other computer i had two different versions so and why does it end up installed in so many different places is my other question like if you about go back to your interpreter there's an icon in two entirely different places yes definitely is very good question i don't quite actually have the answer to that one um i'm trying to think when i feel that i ran into that once actually and it might have been a matter of where i selected during the install process or the download process but um in terms of a default action why would store elsewhere not sure burke to be honest with you but yeah it's interesting on mine if i select the interpreter there's like nine and i don't remember installing any of them and they're just all over the place yeah i feel the the reasons vary i know for me um as i have on my screen right now i have the 64 bit in one place and then i have 32-bit in another place gotcha yeah all righty yeah go ahead oops there we go what'd you say i was telling chat there's ah there's no wrong way to do it just put your python wherever you like yeah all righty speaking of python let's actually now get into some code so on the left here where i have the sidebar these are the files that i have in a folder that's been set up and i'm going to open the hello world file that i have here so within this hello world file it's a very short two lines of code i have a variable msg that stands for message and assigned to it is the string hello world and then we're going to print that variable so there's different ways you can go about running this in the terminal at the top you could select terminal and then you can open a new one and then from there if you were to run for example towards oh yeah it's worth at the top oops you can run without debugging so you have that option there's also this play icon that'll also run the um the uh in scripts as well and then if you right-click in the editor it might be a little difficult to see um screens shifted things a bit but there's also an option there to run python file in terminal and then also if you're more into writing commands you can always do that in terminal as well personal favorite for me is going to be the play button and i don't know i just like it so here i have the output which is going to be hello world in this case if there happens to be any problems down here in the terminal they're going to show up in this problems area just in case you're wondering like where do my problems go so that's a beginning example of doing some coding in python now i have another example here i'm going to close this up and i have a file that's called emoji underscore demo for our purposes here today so within here um i'm using the emoji package which is going to enable me to have an output of an emoji for uh the code that i have here so i'm going to import that and then i have um a print statement here and what it's going to output is i and then the red heart in python for i love python so one thing i do want to point out is because i don't want to have a lot of packages just installed if you will on my computer this would be a good opportunity to create a virtual environment or a condo environment so right now if i were to try to run this i'm going to have an error because that emoji module is not going to be found so instead what i can do is just create a virtual environment in my case i'm going to do that right now and now it's been created i named it.env so visual studio code is going to provide a notification bottom right and it says that it notices a new virtual environment has been created and do i want to select it for the workspace so when that happens i say yes and then what you're going to notice is that in the bottom left side of the window after i select yes we're going to see that that interpreter has changed so now below i have the one that i created called env if i were to select it it's also now an option here in the interpreters that i can select so as you are creating virtual environments same for conda environments they're going to display here now that i have that virtual environment created i need to go ahead and activate it so let me do that very quickly for everyone with my mouse hypo all right so now i have my virtual environment um activated i can tell because i have the name of the environment to the left and so from here i can go ahead and install emoji using pip install emoji it's doing the installation and now the moment of truth if i were to click play let's clear this out so that way you can better see it if i were to click play now or run now i have i heart on python so as you're trying to keep track of the different environments that you have you'll be able to do that in that interpreter um window that i showed so i'm just going to go ahead and deactivate this while i'm here because i don't need it for my next examples so all right yeah you're deactivating there just real quick this is an interesting question if i don't want to see the path and extra lines when i print something what can i do is it possible to just get the printed statement oh good question i feel like i may have done that in the past but i don't remember top of my head have you done that burke uh-huh how how have you done it i i've seen it shortened for sure and i've and i've seen it i've seen the the beginning of or at the end of it uh the little carrot at the end changed as well before some people have used like an emoji at the end or like some sort of icon or i just don't remember how to do it though yeah there's a actually a vs code there's a video on youtube um that a fellow made about how to do this uh and well so we'll have to follow up on that find it and link it in but it is possible i don't remember what it is i think it's a command you have to actually run in your terminal to do that so it's a command you have to give to python uh let's see what else here what else have we got um so here's one that's not directly related to python but techie shadow techie shadow wants to know is there any way you will suggest to promote my coding tutorials and videos no i'm sorry techie shadow we cannot promote your tech tutorials and videos but thank you for asking um all right let's see just looking at what else is in the chat here uh okay i think we're good just a lot of people saying how much they like vs code and can we watch this video later and yeah all right all right so see we're coming up on time uh one thing that i will have a moment to share if that's okay is intellisense within visual studio code so intellisense is going to be useful tools for programming uh you have code completion object definition location of objects as well as various variable declarations so i'm going to demonstrate what that looks like it's a visual studio code feature but we are able to leverage what's available in that python extension so in here i'm going to create a new file clicking the plus button for a new document here in the explorer i'm going to call it circle.py we're going to calculate the area of the circle with this one and now my file is created the first thing that i'm going to do i'm going to i'll take you through some of the um intellisense features as i'm creating this particular script but the first thing that i'm going to do is import the math model to help us out so as i'm typing import what's happening here is that i do have some suggestions and it can autocomplete the when i'm writing in this case it's an import statement so i'm just going to tab and now i have that there once i've done that i can type m for the math module and as i can see i have a lot of different options available and so this is really convenient um especially as you're starting to write more and more code but in this case i'll click math and i'm going to call it um and now from here i'm going to have a variable radius and i am going to set that i'm going to convert that float and now that i have this float what i'm going to start getting now is definitions and this is also going to start bringing in some information that you would find in reference uh documentation as well super convenient that it's brought to you in visual studio code because instead of having to go outside of the editor and have like your browser open in one place and then having the editor open in another screen everything's going to be brought in here which is super convenient but i'm just going to go ahead and you'll see things pop up as i'm typing that but once i have that in here let's see how fast i can type come on and then we're going to go ahead and print that okay control s tubes nice shift ctrl s all right so from here assuming i didn't type anything incorrectly when i run it it's going to ask for the radius let's say it's going to be four if i press enter and then i'll have my answer so that was more to show what intellisense looks like in action now there is one thing i do want to call out um with regards to jupiter notebook support especially for those of you who do things with jupiter notebook and for those of you who um may not be aware there is a visual studio code environment available by going to visual studio and make sure i have the right url vs code.dev and it's in the browser so instead of downloading um the actual editor to your computer and using it there locally you can also use it in the web there are some limitations however if you are programming in python one that i know for sure is going to be the jupiter notebook support however you can open your notebooks and create notebooks here within the editor if you do have the download version of visual studio code so that'll be the final thing i'll just share with you today with regards to what that is that experience is like in visual studio code but as i'm getting that set up just as um just to let you all know you can also do some debugging in here as well as unit testing too so what i have created so far together is um a notebook that i have it's utilizing one of the learning modules that we created for a space jam a new legacy and the output here is going to be some player stats so like what you would find in a in a notebook we have code cells you can add them in here we have kernel in here as well you can run um oh i think i ran everything did not mean to do that but you can um you can run the cells individually nope i didn't do that perfect so let me get rid of that so you can run the cells individually for example and this one might take a little bit there we go and as you're running that um you can keep track of your variables as well so right now i do have variables that have appeared i can open that up and here in a new tab this is where i can have all the variables that are available depending on where i am right now and running this notebook the other thing i'm going to share after i run all is that if you do happen to have any visuals such as that's closest such as graphs and such at the very bottom i have a box plot for example you can view those in the data viewer if you click this icon top left looks like a little graph and here you can zoom in and out very convenient if you happen to have a lot happening on this screen you can export your notebooks as well you can also export these images as well and graphs and then finally if it's helpful for you you can let's see where there's an option to also export the notebook into a python file so in case for those of you who are out there that works with notebooks jupyter notebook support is available just do keep in mind that it's currently not available in the browser version of es code but it's here if you happen to download to your computer so i think we're um at a point where i can take more questions work all right awesome crash course in python and notebooks as a bonus all right so real quick y'all i'm gonna paste in a link to a video from a gentleman named um what is his name make sure i get it right it's renaldo dolphy and he has the answer on how to print out the python it's right there without all the other stuff so it is some changes that he's making he actually has three different ways to do it so that answers that question there all right let's see chat chat what is up um let's see [Music] are there any shortcuts for nested parenthesis to like i am assuming if you have your code and you want to format it so that way they're nested potentially which then would likely be something more of a formatter that you would potentially use um the default in terms of formatters that sounds like a formatter response but um within visual studio code the default for the formatter is going to be oh i had it written down ready to go it's going to be auto pep8 and then the linter is going to be piling in case you're wondering about that but that might be more of a formatter um and you can do some editing there as well back in that settings section that i mentioned earlier that's where you can do some settings for that but i'm hoping that answered questions my camera died there for a second all right what about this one april here's a good one uh i love the editor i just got a small query while running python on my mac vs code by default uses python 2 how can i modify vs code to use the python 3 version yeah how did i do this because i did all of um honestly i did all my book on my mac uh believe it or not so i ran into that as well um after downloading it what i had to do is when i was working with my interpreter i know i had to select a path where python 3 is downloaded and so constantly speaking about that interpreter area that we mentioned earlier so that's where you're going to be able to set that also back in that settings section that i mentioned earlier is where you can set the default um path where is it it's somewhere in here but is it somewhere it's somewhere default interpreter path it's there so you can set that and hopefully that should help i'm trying to think if that's what i did because you don't want to delete the python 2 from your mac that that helps a couple other things run on your mac but um i think that's that's how i was able to overcome that on there here's an interesting question and intellicode they do sound quite similar they sound very similar oh goodness so i know for intelli sense as i mentioned that's going to be just different things that you can utilize around the areas of code completion you have some object definition as well you can locate but intellicode very good question i don't have an answer for that one yeah intellicode is kind of like github copilot it's an ai assisted coding tool so it kind of like watches what you're writing and then it tries to predict what you're going to write next right and so if you you know if you are in javascript and you write console you probably want to do console log and so it will put log to the top of the list so that's the difference uh in and intellisense is what april explained so intellisense is something that's in visual studio code you'll use it all the time until a code is a plugin that you would install if you wanted to use that uh okay let's see so many questions a chat i want to get to all of them but there's there's yeah let's have a notebook question [Music] you like for me to answer the notebooks question burke the use cases thank you somebody put one out no problem so for notebooks if you are doing a couple different use cases if you are typically doing things around the realm of machine learning for example i've seen it used for there's different data use cases and essentially people who are creating and using notebooks it's a way for you to run your different scripts that you have you are able to export your output as well as i mentioned like the graphics and the visuals earlier into like pngs and pds and fegs and you can incorporate that into any sort of research reports that you're doing so i've seen it used in that um in that instance um i've also honestly seen it used um as a way for teachers to teach students how to use python too because they'll have everything set up in there already and you can just run each cell and the output will display there so i've personally seen it used in both of those instances have you seen it using any other instances burke yeah i've seen it used outside of python for like there's a github issues notebook that we have where you can query github repos so if you're like us and you have a lot of github a lot of open source you're trying to figure out what the status and how many open issues you have across repos it's really good for that kind of stuff i mean it's it's a scratch pad for me so right if i'm just trying to mess around with some code i'm going straight to a notebook i prefer that environment um okay let's see here that's a great question um what else have we got uh there's several questions on this april i saw at least yeah so bug python do i have a quick moment bert to show on the screen you you're over time we're gonna do it anyway we're gonna do it anyway okay we're gonna do it anyway because lucky for everyone i have something set up here so um with debugging you're going to utilize the run in the um debug uh view that's in here and so what i have on the screen is a short simple script that takes numbers in a list and then it totals them multiplies it by two gives you the output so in here you can set breakpoints we have little red dots that appear um you can set them at different places we're able to keep track of where break points are located variables as well when you're ready to run things you can do run and debug you can select your configurations um we have a python python one if you're doing things with django as well as flask for example there's different configurations available there and you can modify those configurations too selecting python file if i go ahead oops it's already running so as um as it starts i can i can continue i can step i can step into those commands are going to be here at the top of the screen so in this case if i continue i'm now into that function here on the left is where i'm keeping track or the editors keeping track of my variables down below a little difficult to see but i do have my break points that are here in their locations with their line number stepping into this one for example let me keep going back at the top i know this is like super quick everyone but back at the top now as i'm keeping track of my variables um you're going to start seeing things change as i start to get new variables so now i know what num is for that um so on and so forth so that's like super duper quick overview of how you can debug and vs code for python i would suggest checking out the documentation for a more thorough um deep dive into doing debugging with vs code for python but there's a lot of functionality there even here on the screen as i have you can also watch um watch as well as you're doing the uh debugging and we also have a debug console as well where you can also um enter as you are debugging so super quick hope that answered the question yeah that was great so we're over time we have there's so many comments for you here april chat i wish we could get to the to all of these questions here perhaps we need to have april back or do another i think we definitely need to do more python is what i've learned from this uh y'all been awesome thank you april for uh coming on the stream and sharing the python with us it was lovely yeah no problem all right chad's the only thing left for you to do is head over and grab april's book on python you're going to want to do that it's going to look there it is it's going to look great on your bookshelf no matter what and and you're going to want to be back here next week next thursday for the next live stream uh so check that out and we will see you then have a fantastic weekend y'all bye
Info
Channel: Visual Studio Code
Views: 32,776
Rating: undefined out of 5
Keywords: vs code, vscode, visual studio code
Id: 7FltByLPnrg
Channel Id: undefined
Length: 29min 47sec (1787 seconds)
Published: Fri Nov 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.