- How to Add Executables to your PATH in Windows
- How To: Add Path to Python in Windows
- How To: Add Path to Python in Windows
- April 2021 Update:
- CONCLUSION
- How to add Python to Windows PATH
- Method 1: Install a Recent Version of Python
- Method 2: Manually add Python to Windows Path
- Step 1: Navigate to the Windows Environment Variables screen
- How do I add to the Windows PATH variable using setx? Having weird problems
- 12 Answers 12
How to Add Executables to your PATH in Windows
May 25, 2016 · 2 min read
While this may seem obvious to some, for non-native Windows users like myself, it took way more time than it should have to get my favorite executables running from the command line. To shed some light on this, I decided to put together a walkthrough on how to get Ruby running from the command line. Ruby is just an example, it works exactly the same way for everything from Appium to Maven.
The Problem: I can’t run my Ruby file from the command line.
After counting backwards from 10, I need to find where Ruby was installed on my machine. In my case, the installer put it here: “C:\Ruby22”. I then need to find where the executable files are located, which is usually the “bin” folder.
Having found my Ruby executable “ruby.exe”, I copy the file path “C:\Ruby22\bin”. Now I need to find and edit my PATH environmental variable.
Step 1: Right click on the Windows Logo and click System
Step 2: Click on Advanced System Settings
Step 3: Click on Environment Variables
Step 4: Select your PATH variable and click edit
Step 5: Click New and add the file path to the list
How To: Add Path to Python in Windows
If you installed Python on Windows using the default installation options, the path to the Python executable file was not added to the Windows path variable. The Path variable lists the directories that are searched for for executables when you type a command at the command prompt. If you add the path to the Python executable file, you can access the python.exe file by typing the python keyword (you do not have to specify the full path of the program).
Whenever you need Python to import a module, Python looks at all the files in its path list to find it. Information on the path comes from three sources:
- Environment variables : Python environment variables, such as PYTHONPATH, tell Python where to find the modules on the disk.
- Current directory : You can change the current Python directory so that it can find all the modules used by your application.
- Default directories: Even if you do not define environment variables and the current directory does not provide usable modules, Python can still find its own libraries in all the default directories that are included in its own path information.
It is useful to know the information of the current path, because the absence of a path can cause your application to fail. The following steps show how to get information about the path.
How To: Add Path to Python in Windows
Think about what happens if we type the python command at the command prompt and the path to this executable is not added to the Path variable :
April 2021 Update:
We now recommend using this tool for your error. Additionally, this tool fixes common computer errors, protects you against file loss, malware, hardware failures and optimizes your PC for maximum performance. You can fix your PC problems quickly and prevent others from happening with this software:
- Step 1 : Download PC Repair & Optimizer Tool (Windows 10, 8, 7, XP, Vista – Microsoft Gold Certified).
- Step 2 : Click “Start Scan” to find Windows registry issues that could be causing PC problems.
- Step 3 : Click “Repair All” to fix all issues.
C:\>python
Python’ is not recognized as an internal or external command,
functional program or batch file.
As you can see on the output above, the command was not found. To run python.exe, you must specify the full path of the executable file :
C:\>C:\Python34\python –version
Python 3.4.3
For Windows 10/8/7:
- Open System Properties (right-click on Computer in the Start menu, or use the Win+Pause shortcut).
- On the sidebar, click Advanced System Settings.
- Click on Environment Variables………….
- In the System Variables pane, select Path.
- Click on Modify
Add the Python path at the end of the list (the paths are separated by semicolons). For example:
For Windows XP:
- Open the system properties (enter them in the Start menu or use the Win+Pause key combination).
- Go to the Advanced tab
- Click on Environment Variables………….
- Select PATH in the System variables field.
- Click on Modify
Add the Python path at the end of the list (the paths are separated by semicolons). For example:
Test in a new terminal window or when using a terminal integrated in a text editor, close and restart your editor or the changes are not applied.
CONCLUSION
Python is a programming language that was first published in 1991. It has an application that can be used on multiple operating systems, and developers can write and develop new code on it. Python is one of the most widely used programming languages because it offers many possibilities and extensive support for the developer.
Each time the user enters the words “python” in the prompt, he returns an error and the entire path must be specified for it to work correctly. Indeed, the prompt must find the file “python.exe” to load the output, and it can only do so if the full path has been specified. This article shows how to continuously add a path to Python to solve this problem. Then, you can run “python.exe” without having to specify the full path.
CCNA, Web Developer, PC Troubleshooter
I am a computer enthusiast and a practicing IT Professional. I have years of experience behind me in computer programming, hardware troubleshooting and repair. I specialise in Web Development and Database Design. I also have a CCNA certification for Network Design and Troubleshooting.
How to add Python to Windows PATH
There are few ways in which you can add Python to Windows PATH. In this guide, I’ll share with you two methods that you can use to add Python to Windows path:
- Via the installation of a recent version of Python
- Manual entry of the paths
But why would you want to add Python to Windows path in the first place?
Well, if you try to install a Python package using PIP for example, you may get the following error in the Windows Command Prompt:
‘pip’ is not recognized as an internal or external command, operable program or batch file
To overcome this error, you may apply any of the two methods described below.
Method 1: Install a Recent Version of Python
You can easily add Python to Windows path by downloading a recent version of Python, and then checking the box to Add Python to PATH during the installation.
Before you proceed, you may choose to uninstall your previous version of Python if needed.
In my case, the latest version of Python that was available to download was version 3.7.2.
In the Python installation box, just check the box to add Python to PATH as below:
Finish the installation, and you should be good to go.
Alternatively, you may manually add the paths into the Environment variables.
Method 2: Manually add Python to Windows Path
If you wish to stick with your previous version of Python, you may apply the steps below to manually add Python to Windows path.
Note that I’ll be using Windows 10 to demonstrate the steps, but similar principles would apply for previous versions of Windows.
Step 1: Navigate to the Windows Environment Variables screen
To navigate to the Windows Environment Variables screen, where you can add/edit your paths, simply right click on the ‘This PC‘ icon. Then, select ‘Properties.’
Next, click on the ‘Advanced system settings‘
Finally, click on the ‘Environment Variables…‘
That should take you to the Environment Variables screen, where you can add/edit your paths.
Click on ‘New…‘ to add the ‘Path’ variable (note that if your ‘Path’ variable already exists, then click on ‘Edit…’ instead):
You should then see the following box, which will allow you to add/edit variables:
Before you type any values, you’ll need to locate the relevant Python paths. The paths that you’ll need to get are:
- The Python application path, which is the folder where you originally installed Python; and
- The Python Scripts path. The Scripts folder should be located within the Python application path.
Here is how my Python application path looks like:
And this is how my Python Scripts path looks like:
Now let’s fill the New User Variable box that you saw earlier:
For the Variable name, type ‘Path‘.
For the Variable value, copy the full Python application path, then use semicolon (as highlighted in yellow below), and finally copy the Python Scripts path.
This is how my Variable value looks like:
Put all the values together in the New User Variable box:
Press ‘OK’ and you would then see your new Python Path under the ‘User variables’ section. Don’t forget to press ‘OK’ again so that the changes will get implemented.
That’s it! You just added Python to the Windows Path.
You’ll now be able to install Python packages easily, by opening the Windows Command Prompt and then typing:
pip install package name
For example, to install the pandas package, simply type ‘pip install pandas’ and then press Enter:
Similarly, you may upgrade PIP by typing the following command:
How do I add to the Windows PATH variable using setx? Having weird problems
I want to modify the Windows PATH variable using setx . The following works at least 50% of the time on Windows 8:
If it gives the error «the default argument can only be used 2 times», then the following works some of the time:
The difference is that we wrapped the second argument in quotes. I believe the quotes are necessary when %PATH% expands to include spaces.
However, I have encountered some weird problems on Windows 7. On one particular Windows 7 machine, I had this problem:
Then it says «Error: Truncated at 1,024 characters.» Now let’s check what PATH contains:
. and it is cut off at 1,024 characters. It ran over because of the duplicates. Also interesting: The value of PATH changes despite the fact that setx raised an error and did not say «Success».
I was able to repeat this strange behavior several times (luckily I had saved the original contents of PATH).
At the moment, the only surefire way I know to append to the PATH is the following:
Copy the contents of PATH into a text file and manually add ;C:\Python27\;C:\Python27\Scripts\ to the end of the PATH.
Copy the whole thing out of the text file.
That process works every single time on both Windows 7 and Windows 8.
I should really be able to do this in one command. What am I doing wrong?
«expand» in both hklm and hkcu mean expand to hklm. setx/m qwe %JAVADIR%\bin and setx/m javadir asdfg in either order. Then open a new cmd and do echo %qwe% : works as expected. – Pacerier Jul 29 ’17 at 11:49
12 Answers 12
Run cmd as administrator, then:
The /M option sets the variable at SYSTEM scope. The default behaviour is to set it for the USER.
TL;DR
The truncation issue happens because when you echo %PATH% it will show the concatenation of SYSTEM and USER values. So when you add it in your second argument to setx, it will be fitting SYSTEM and USER values inside the USER var. When you echo again, things will be doubled.
Additionally, the /M option requires administrator privilege, so you need to open your terminal with «run as administrator», otherwise setx will complain with «access to registry path is denied».
Last thing to note: You won’t see the new value when you echo %PATH% just after setting it this way, you need to close cmd and open again.
If you want to check the actual values stored in registry check this question.