From the course: Intermediate Python for Non-Programmers

Python on Windows

- [Instructor] In this video, we're going to walk through how to get Python up and running on your Windows computer. Now, if you have a Mac or a Linux machine, go ahead and skip to the next video, that's going to be for you. And if you came from my previous course, and you're saying, "Hey, Nick, you know, "We ran Python in the browser last time. "Can't we just keep doing that?" Yes, you totally can, and that's fine. But I would like to show you how to get Python up and running on your Windows computer, because what if you don't have internet access? What if you want to be able to edit or manipulate files on your own computer? We're going to get to that later in the course. I think it's a good skill to be able to run Python on your own computer. But if you'd like to use the browser, you're more than welcome to. So first thing that we got to do is check and see if Python is already on our computer. You may have already had it pre-installed. It may have come with the operating system. But to do this check, go down into the search bar and type CMD and hit Enter. This is going to open the command prompt. The command prompt is where we're going to be running our Python code. So to check and see if Python is installed, we're just going to type out lowercase python and hit enter. Now if you don't have it installed, there's a chance you'll get, like me, this popup, where the Windows store comes and it says, hey, let's download Python 3.10 for you, or whatever the current version of Python is. As long as you've got Python 3 point something, I think really even just Python 3.5 or 6 and above is going to be fine. You can go this route. You can use the Windows Store to go ahead and install this. I'm a little bit more of a fan of downloading it directly from the Python website, so let me show you how to do that. So you're going to want to go to a browser, and go to python.org. And once you're on the Python website, you're going to want to hover over downloads here, and you'll want to grab whatever the latest version is. Again, as long as it's Python 3, you don't have to worry about what the next number is, in this case it's .10, but by the time you're watching, it may 11, 12, 13, whatever, it's going to be fine. So go ahead and start that download process. Once that download is finished, you can click on the EXE that you've downloaded, and this will start the install process. So I would note here, make sure that you have this add Python 3.10 to path selected here. This is going to help you as you do your installation. So let's just go ahead and just do the top button here. You'll have to put in your password, so go ahead and do that for your computer. And with that in place, the install process is going to start taking place. So we'll go ahead and jump forward to when this is all finished. All right, so now that you're done with that, go ahead and hit close on the installer here, and you're going to want to go back to your command prompt here and just exit out of that, and let's open it one more time. So again, CMD and hit enter. That's going to open up the command prompt. And let's now try typing out python, all lowercase, hit enter, and look at this. You can see now we get some text here, and it's showing us that we have Python 3.10.7 installed. And again, your version's going to be different than mine, but as long as it's 3 dot something, you're good to go. So you'll notice it's a little bit hard to get out of here, right? If you just start typing some information, it's actually running Python code here. If you need to get out, all you need to do is just type exit, all lowercase, within open and closed parentheses, and this is going to get you back to your regular command prompt. Again, you can also just make this really simple and say, you know, I'm just going to close out of this, and again, you just go back to your search bar, CMD, and you can get the command prompt open again. So now that you've got Python on your computer, let's go ahead and write some Python code and test it so you can see how we run Python code on Windows. So first, we're going to need some sort of code editor. And really with Python, you could use any old text editor, but there are some big advantages to using a code editor. In my opinion, the big one is the coloring that comes with it, so that you can see the differences between variables, strings, numbers, functions, things like that. All right, a quick update here. The code editor that I used to film this course, Atom, has now been discontinued. So, no fear, there's a great replacement. I want you to check out Visual Studio Code. So go ahead and open up your browser, and just go ahead and search for Visual Studio Code. Okay. It will probably just be the top link here, code.visualstudio.com. Now one thing to note there is Visual Studio, which is working with specifically .net stuff, but we want Visual Studio Code. So make sure you're downloading Visual Studio Code. But go ahead and hit this download button. I'm sure as time goes on, this landing page will look a little bit different. But again, download Visual Studio Code, that's what I recommend. You can use any code editor that you want, but I think this is a great choice. It's very popular and has a lot of momentum behind it. So go ahead, download this, get it installed, and then I'll pick back up with you. All right, now that I've got Visual Studio installed, you'll see when you launch it a little welcome screen probably somewhat similar to this. And again, the rest of this course I'm going to be using a different code editor, although they're going to look quite similar, so don't be thrown off from that. They have all the same basic commands, like if you need to, you know, create a new file here, you could just go file, new file. It's all going to be very similar. I do have one little cool pro tip I'd like to show you at the end of the video here. So we'll keep moving forward, but keep an eye out for that at the end of this video. So the first thing that we want to do is we want to start a new file. So I'm going to go and say file, new file. And let's just go ahead and do the classic hello world. So we're going to print this out. I'm going to say here hello there, just to be a little bit more friendly and personalized. And we're going to want to save this. So let's go ahead and do a save here. You could do CTRL+S, and that will be good to get in the flow of that, but for now, I just want to show you how we can save this. And choose a place to save your code. I recommend doing this on the desktop, 'cause that's what I'm going to be doing for the course here. But if you've got a place that you'd like to save and run your code, pick that place. And for the name here, you can call this file whatever you want, but it's got to end in a .py file. And the reason that this is so important is I want you to notice the color of the text here. It's all grayed out. But as soon as I give this a name, like I'm going to call this hello.py, and I save this to my desktop, look what happens. We get that special coloring to say this is a string and this is a function here. This is going to be really helpful. Like if you know we're setting some sort of number here, you can see these colors, these really help you as you're coding to catch mistakes and different changes that you've made. Okay, so we've written some code we have it here inside of our code editor. How do we run this Python code? We want to see the string hello world printed out. Well we need to go back to our command prompt. So let's go ahead and open that. And this command prompt, in order to run that code, we need to get to our desktop. So I think a good way to sort of visualize and understand how this command prompt is working is this is a text way to interact with Windows. Typically you use things like the file explorer here, and you say, hey, you know, I'm going to go to my documents or my pictures, whatever it is. But the command prompt is the text way to move around your computer. So right now it's telling us we are currently at C:\users\zappycode, that's the name of my user account on the computer. And so if we want to see the same thing in the file explorer, I'm going to go to C, users, and I'm going to click on zappycode. And now we're in the exact same location. So I want you to see this is the text version in command prompt, this is what it looks like in the file explorer. Now I'm trying to get to my desktop. If I want to get to the desktop in File Explorer, I just double click on it and look, there's my hello.py file. It doesn't show me the .py, but it does tell us this is a Python file. So we know that is a .py. But the question is how can we do that same thing here inside of the command prompt? Well, we use a command called cd. It's short for change directory, directories are the same thing as these folders here. So if we want to move to the desktop, we're going to say CD, space, and then we have to make sure it's capitalized, We're going to type out desktop. And once we do that, it shows us we are now inside users, zappycode desktop. and to see if our hello.py file is there. If you ever want to see whatever files are inside of a directory, you can just type lowercase dir, again, short for directory. And it's going to show you all the things in that directory. And look, there's that hello.py. So that we know we're now in the same place. This was the same thing as just clicking here and seeing that hello.py. Now if you ever get lost again, you can close the command prompt and reopen it. If you ever want to go back inside of your directory you can always do CD, space, dot dot. And that moves you back one directory. You see how we went from the desktop back to the zappycode folder. And again, to see what's inside of here, we can just do that dir, again, dir shows you everything that's inside of your current directory. So we can see this and say, hey, I want to go to the desktop, so I'll do cd. And a quick little pro tip here, if you want to go to the desktop, if you just start typing desk, and you hit the tab, it can autocomplete it for you. It's going to say, hey, you know, there's nothing else here that has, that starts with D-E-S, I'm assuming it's the desktop. And so that tab can help you to quickly get to where you want to be. All right, so we're on that desktop, again, Let's hit dir, make sure that we can see, there's the hello.py, how do we run hello.py? All we got to do is just type lowercase python, space, hello.py. And when we do that, look, we get hello there. That's the thing that we printed here in our code. And to see how we're going to be moving throughout this course, it's going to be, you know, let's make some change to our code. Instead of hello there, I'm going to say hello son. I'm going to give my kid a little shout out. I'm going to save that by doing my CTRL+S. And now I'm going to come back to the command prompt, and I'm going to run that same Python hello.py again, you can use tab here, and look at that. Now it says hello son. So this is how we're going to be working in the course, is we're going to make changes to our code here in the editor, and then we're going to come to our command prompt and run them. And another great little pro tip is if you ever want to just do the last command you did, you hit the up arrow on your keyboard and it brings back your last command. And then you can hit enter. You'll get into this flow, but it's like you make a change inside your code, you hit CTRL+S, you come back to the terminal, hit the up key, enter, and now you're rerunning your Python file. So this should be everything that you need to move forward. Again, just a little pro tip, in the course, when I'm running my code on MacOS, I have to type out Python three and then the name of my file. You'll notice if you try and do this in Windows, it says, hey, we don't even know what's going on there. For you, you just need to do Python and then the name of your file. So just keep that in mind. And again, I'm going to refer to this command prompt as the terminal, but for you, in Windows, it's going to be called the command prompt, okay. So go ahead and skip the next video, which is going to be for the Mac and the Linux users. And let's go ahead and start first with classes. Okay, I'll go ahead and see you in that video. So here we are, I wanted to show you a quick little pro tip. If you are using Visual Studio Code, something fun that you can do. And that's that you can actually run the command prompt inside of Visual Studio Code, the same place that you're editing your code. So if you go up here to terminal, and you say new terminal, this will essentially have a command prompt for you. They call it terminal, which it kind of helps that you know in the Mac world we're referring to that as a terminal, you'll hear me referring to that through the rest of the course. But this is the same thing as if you had opened a command prompt, right. Like if I wanted to go to the desktop, I can say CD, space, capital, desktop, it does the autocomplete for me. And I can say I want to do Python hello.py. And look, it runs the code. So what's neat about this is that it's just a little bit simpler to say, hey, you know, I want to change this to hello world. I'll make my changes, hit save. I come down here to my terminal, hit the up arrow, enter, and I can see those changes just all right here in the same window. Now you can choose to do this, you can choose to use the command prompt just like we do in the course. It's completely up to you, but I thought you'd like to see this. All right, with that, let's go ahead and move forward.

Contents