How to Add Python to PATH

Windows permits the configuration of environment variables in both the User and System levels, either as permanent settings or temporarily within a command prompt. For enhanced Python accessibility via a command prompt, it's advisable to modify certain default environment variables within Windows.

To temporarily set environment variables , open Command Prompt and use the set command:

C:\>set PATH=C:\Program Files\Python 3.6;%PATH%

How to set python path in windows

To permanently modify the default environment variables :

My Computer > Properties > Advanced System Settings > Environment Variables > Edit

  1. Right-click 'My Computer'.
  2. Select 'Properties' at the bottom of the Context Menu.
  3. Select 'Advanced system settings'
  4. Click 'Environment Variables...' in the Advanced Tab
  5. Under 'System Variables': Click Edit

Add python's path to the end of the list (the paths are separated by semicolons(;))


How to add to the pythonpath in windows

Using Python from a command windows?

Open a command prompt window (press Windows+R, type in cmd, and hit enter).

Just type "python" on the command line and see if you get an error or not. If you see a response from a Python interpreter it will include a version number in its initial display.


Python Download and install

Success, now you can start programming on Python .

Python is not recognized..


python path windows 10

If you still get the Python is not recognized as an internal or external command, operable program or batch file error, there is something wrong with your Path variable settings . Moreover, you will have to reopen all command prompt windows in order for changes to the Path variable take effect.

Setting Python Path in Unix or Linux

To add the Python directory to the path for a particular session in Unix/Linux :

csh shell: type setenv PATH "$PATH:/usr/local/bin/python" and press Enter.
bash shell (Linux): type export ATH="$PATH:/usr/local/bin/python" and press Enter.
sh or ksh shell: type PATH="$PATH:/usr/local/bin/python" and press Enter.
  1. /usr/local/bin/python is the default path of the Python directory.

What is PYTHONPATH?

PYTHONPATH functions as an environment variable that enables the inclusion of supplementary directories to the sys.path directory list in Python. Typically, it's unnecessary to configure these variables during installations, as Python inherently discerns the location of its standard library. PYTHONPATH aids in the search for imported modules, essentially assisting in module lookup. Thus, when you import modules within your Python scripts, PYTHONPATH is additionally consulted to identify directories potentially containing the sought-after module.

How to add to the PYTHONPATH in Windows?

My Computer > Properties > Advanced System Settings > Environment Variables >
  1. Click the "New" button in the top half of the dialog, to make a new user variable.

  2. Give the variable name as PYTHONPATH and the value is the path to the code directory.

python path in ubundu
  1. Click OK and OK again to save this variable.

In order to confirm PYTHONPATH , open a Command Prompt and type:

echo %PYTHONPATH%

Now you can confirm the environment variable is correctly set.

  1. It's essential to differentiate between the PYTHONPATH environment variable and the Python PATH environment variable. The latter serves the purpose of aiding the operating system in locating executables from any location. For instance, if you enter "Python" in your Command Window, the system will consult the PATH variable to identify directories potentially housing the "python" executable. This distinction is crucial to avoid confusion between the two variables.

Conclusion

To add Python to the PATH environment variable, follow these steps: Open the command prompt (Windows), or terminal (macOS, Linux) and navigate to the Python installation directory. Locate the "Scripts" folder within the Python directory, copy its path, and then append it to the PATH variable using the system's environment variables settings. This enables the system to execute Python commands from any location within the command prompt or terminal.