How To: Add Path to Python in Windows



RECOMMENDED: Click here to fix Windows errors and optimize system performance

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 :



February 2020 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.

download



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:

  1. Open System Properties (right-click on Computer in the Start menu, or use the Win+Pause shortcut).
  2. On the sidebar, click Advanced System Settings.
  3. Click on Environment Variables………….
  4. In the System Variables pane, select Path.
  5. Click on Modify

Add the Python path at the end of the list (the paths are separated by semicolons). For example:

C:\Windows;C:\Windows\System32;C:\Python27

For Windows XP:

  1. Open the system properties (enter them in the Start menu or use the Win+Pause key combination).
  2. Go to the Advanced tab
  3. Click on Environment Variables………….
  4. Select PATH in the System variables field.
  5. Click on Modify

Add the Python path at the end of the list (the paths are separated by semicolons). For example:

C:\Windows;C:\Windows\System32;C:\Python27

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.

https://stackoverflow.com/questions/12257747/permanently-adding-a-file-path-to-sys-path-in-python



RECOMMENDED: Click here to troubleshoot Windows errors and optimize system performance