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.
