Join Joe Marini for an in-depth discussion in this video Installing Python, part of Learning Python.
Let's begin by making sure that Python is properly installed and configured on your computer. Now, the good news is if you're watching this on a Macintosh or a Linux, then chances are you've already got Python installed on your system. The Mac ships with Python, as does Ubuntu Linux, so you should be good to go. But you can make sure that you have the right version by following along with me. Now, here on my Windows machine, I'm going to type the Windows key and R to open a command prompt. So I'm going to type cmd. And if you're on the Mac, you can start the terminal program or whatever terminal program you use on Linux to follow along.
So I'm going to start this up, and I'm going to type the word python, followed by dash dash version. And you can see that I'm using Python 2.7.5 on my computer. Now, if you didn't get a result that looks like this, Python followed by a version number. If you got something like python is an unrecognized command or something like that, then that means that Python is not configured for your computer and you need to go get it. So let's go do that on the Python website. This is the Python website, located at python.org, and I'm going to scroll down just a little bit.
And you can see here that there are two versions of Python. There's the 2.7 line, and then there's the 3 line. 2.7 is the original version of the Python language, whereas the 3 version is the new, updated modern version. Now I'm going to be using the 2.7 version in this course because it's still very widely supported by a variety of providers. Google App engine, for example, supports 2.7. The Mac uses 2.7 as its default. So, 2.7 is pretty widely used, and the code that I'm going to be showing you in this course, as I said earlier, pretty much works on both versions 2.7 and 3.x.
There's just a couple of tweaks you need to make in order to get the code to work. Sometimes a library is named slightly differently or for example the print statement is a function on the 3 line versus a statement on the 2 line. You'll see the differences in the example snippets that I have provided for you. All right, so if you need to install Python, chances are it's going to be on a Windows machine. And you can click on the Windows installer right here, or if I scroll back up you'll notice there's a download section, and if I click on Download there's releases for Windows, for Mac, and for other systems as well.
So, you can choose how you want to install it. So, once you run the installer that will put Python onto your computer, and we can go back to the command prompt and make sure it's there. Now, one other thing you may have to do, and Python 3 usually takes care of this, and Python 2.7 installer sometimes takes care of this as well. But if you install Python and you're still getting the error message when you type python dash dash version, that's because Python has not been added to your path environment variable.
In other words, the operating system doesn't know where to find the Python executable. Now on Windows, to fix this problem is pretty simple. All you need to do is type setx, which is going to set an environment variable, and I'm going to type path, and then in quotes I'm going to type the path to wherever I installed Python. In this case, it's going to be C:\Python27. 'Kay. And then, I'll just execute this command.
Now, it's a funny thing about Windows. When you do this, this will not take effect for the current command prompt that you have open right here. You'll need to close this window, and then open a new one, and then the path environment variable will be set properly. So once you've got Python installed, we can go on with the rest of the course.
- Installing Python
- Choosing an editor/IDE
- Working with variables and expressions
- Writing loops
- Using the date, time, and datetime classes
- Reading and writing files
- Fetching Internet data
- Parsing and processing HTML