Resource mentioned in this lesson: Everything app
Adding Python to PATH on Windows
00:00
Now let’s add Python to PATH on Windows. This will let you use the python command from the command line.
00:07
First, you’re going to need to know where your Python executable was saved to. So you’re looking for the folder that contains python.exe. When you use the default settings in the official installer, the location it’s going to be saved to is here inside of your user folder, AppData, Local, Programs, Python, and then Python3X.
00:30 Where 3X is the version of Python that you installed. So I have Python 3.13 and I’d be looking for Python313. Some other locations you could try would be in the C drive, Python3X, or inside of Program Files.
00:46
And those would only be for if you installed Python for all users on your computer. So to verify the Python location, you can open up the file explorer and try to run the python.exe file and make sure it runs the Python console.
01:03 We’re going to try it with the default location. So you can open up your file explorer and go to the C drive, Users, your username, and then AppData. If you don’t see AppData, it’s because it’s a hidden folder.
01:25
Show, and then make sure Hidden items is checked. You can also make sure that File name extensions is checked so that when we find Python, it’s going to say python.exe.
01:38
So go into AppData, Local, Programs, and here is Python. Now there’s also the Python Launcher folder where the py command can be found. And then Python313, which is what we’re looking for.
01:53
And double-click python.exe and it opens up the Python console. So that’s the file we’re looking for, the one to run when we run the python command.
02:07
And the folder, you can copy the path by going to the top where the breadcrumbs are and copying that path. So that’s what we’re going to be adding to PATH.
02:19
Now, if you weren’t able to find your python.exe at one of these locations, don’t worry. At the end of this lesson, I’ll show you how to search your computer and a few different methods for finding it.
02:32 For now, since I think that’s a bit of an edge case, I’m just going to assume you found it now and we’ll look at how to actually add it to your environment variables.
02:43 Windows has a special GUI for editing environment variables. To find it, you can go search for “environment variables” and you should find a match that says “Edit the system environment variables.” And it’ll open up the System Properties here and you can click the Environment Variables button.
03:05 Or depending on which one you clicked, it might just open this one directly. Now in Environment Variables on the top, there’s going to be the user variables for your specific user. And then on the bottom, there’s the system-wide variables for all users.
03:22
You can click the PATH on the top user variable one and Edit or double-click and then you can edit the environment variable and each path is going to have its own line.
03:36
So click New and paste the path that we found earlier and then you can move it to the top so that it’s the first one that’s searched. Now in this view, if you have other problems related to your PATH environment variable, you can use this window to delete things, edit things, or reorder things.
03:57
So now that it’s there, let’s click OK, OK, OK. And you won’t be able to use the python command just yet.
04:07
It’s still not going to be found. But if you open up a new terminal PowerShell view, now the python command is located.
04:22
If you weren’t able to find python.exe at any of those previous locations, here are a few other things you can try. If you have PyLauncher installed, there is a list paths option that will print out the locations of any Python versions that were found. So you can try py --list-paths and for each version that it finds, it will point to where that file actually lives on your computer.
04:52
Make sure when you’re adding to PATH, you’re just adding the folder, not the file itself.
04:58 Another option is using the file explorer to search.
05:03
So navigate to the drive or location you want to search in. I’m going to look in Local Disk C and on the top right, there’s a search bar and you can look up python.exe.
05:17 But note, this does take a while. On my computer, it takes about a minute and a half to see all the results.
05:26
Another option you might choose is to download another application that searches your computer faster. I’ve got Everything installed. The download link for it is at https://www.voidtools.com/downloads/ and this is what it looks like.
05:43
And I can search for python.exe and you can see it gives me those search results super fast. If you don’t see any results or you don’t see any files being searched at all, then you can go to Tools,
06:01 Options, Folders, and make sure that there’s actually a folder here that it’s searching in. I’ve got my C drive. You might need to add yours.
06:13
And then you have to figure out what file you actually are looking for. It should match python.exe exactly. And the folder location should look like it’s at the root location of a Python program, like this one in Python313, and not this one inside of WindowsApps, Microsoft, and then a bunch of random numbers and letters. And then you can also double-click on this file, make sure it opens up python.exe.
06:42 And you’ve found your Python location.
06:46
Okay, so now that you know how to modify PATH, in the next lesson, you’ll learn how to view PATH and other environment variables directly from the command line.
Become a Member to join the conversation.
