If you have recently installed Python on your Windows 10 computer and are having trouble running Python scripts or accessing Python’s functionalities, it’s likely that you need to add Python to your system’s PATH variable. In this blog post, you’ll learn step-by-step how to add Python to your PATH in Windows 10.
What is the PATH variable?
The PATH variable is a system environment variable that contains a list of directories where the system looks for executable files. By adding Python to the PATH variable, you are telling Windows where to find the Python executable, so you can run Python scripts and use Python commands from the Command Prompt or PowerShell.
Step 1: Find your Python installation path
First, you need to find the path to your Python installation. By default, Python is installed in the C:UsersYourUsernameAppDataLocalProgramsPythonPythonXY directory, where X and Y represent the major and minor version numbers of Python (e.g., Python38 for Python 3.8).
However, if you chose a custom installation directory during the Python installation process or are using a different version of Python, the path might be different. To find your Python installation path, open the Windows Start menu and search for “Python.” Right-click on the Python application and select “Open file location.”
Step 2: Copy the Python installation path
Open the folder containing the Python executable (it should be named python.exe). Click on the address bar at the top of the File Explorer window to select the folder path, then right-click and select “Copy” to copy the path to your clipboard.
Step 3: Open the Windows Environment Variables settings
Now you need to access the Windows Environment Variables settings. Right-click on the Windows Start button and select “System.” In the System window, click on “Advanced system settings” on the right side. This will open the System Properties window.
In the System Properties window, click on the “Environment Variables” button at the bottom right corner to open the Environment Variables settings.
Step 4: Edit the PATH variable
In the Environment Variables window, find the “Path” variable in the “System variables” section. Select it and click on the “Edit” button.
In the Edit Environment Variable window, click on the “New” button and then right-click on the empty field that appears. Select “Paste” to paste the Python installation path that you copied earlier. Make sure there are no extra spaces or characters in the path.
Step 5: Add the Python Scripts directory (Optional)
Adding the Python Scripts directory to the PATH variable allows you to run Python-related tools and scripts that are installed in the Scripts directory, such as pip (the Python package manager).
To do this, simply click on the “New” button again and paste the Python installation path you copied earlier, but this time add Scripts at the end of the path. For example, if your Python installation path is C:UsersYourUsernameAppDataLocalProgramsPythonPython38, the Scripts directory path should be C:UsersYourUsernameAppDataLocalProgramsPythonPython38Scripts.
Step 6: Save your changes
Click on the “OK” button to close the Edit Environment Variable window, then click “OK” again to close the Environment Variables window, and finally click “OK” one more time to close the System Properties window.
Step 7: Verify the Python PATH configuration
To make sure that Python has been added to the PATH variable correctly, open a new Command Prompt or PowerShell window and type the following command:
If your Python installation was added to the PATH variable successfully, you should see the Python version number displayed in the command output. Now you can run Python scripts and use Python commands from anywhere on your system without having to specify the full path to the Python executable.
Adding Python to the PATH variable in Windows 10 is a straightforward process that makes it easier to work with Python scripts and tools on your system. By following these steps, you’ll ensure that you can run Python scripts and use Python commands from the Command Prompt or PowerShell without any issues.