## 3.6.1 Excursus: Setting environment variables 

Windows allows environment variables to be configured permanently at both the User level and the System level, or temporarily in a command prompt. 

To temporarily set environment variables, open Command Prompt and use the$_{set}$ command: 

C:\> set PATH =C:\Program Files\Python 3.9; %PATH% C:\> set PYTHONPATH =%PYTHONPATH% ;C:\My_python_lib C:\> python 

These changes will apply to any further commands executed in that console, and will be inherited by any applications started from the console. 

Including the variable name within percent signs will expand to the existing value, allowing you to add your new value at either the start or the end. Modifying PATH by adding the directory containing python.exe to the start is a common way to ensure the correct version of Python is launched. 

To permanently modify the default environment variables, click Start and search for ‘edit environment variables’, or open System properties, Advanced system settings and click the Environment Variables button. In this dialog, you can add or modify User and System variables. To change System variables, you need non-restricted access to your machine (i.e. Administrator rights). 

Note: Windows will concatenate User variables after System variables, which may cause unexpected results when modifying$_{PATH}$ . 

The$_{PYTHONPATH}$ variable is used by all versions of Python 2 and Python 3, so you should not permanently configure this variable unless it only includes code that is compatible with all of your installed Python versions. 

See also: 

https://www.microsoft.com/en-us/wdsi/help/folder-variables Environment variables in Windows NT 

https://technet.microsoft.com/en-us/library/cc754250.aspx The SET command, for temporarily modifying en- vironment variables 

https://technet.microsoft.com/en-us/library/cc755104.aspx The SETX command, for permanently modifying environment variables 

https://support.microsoft.com/en-us/help/310519/how-to-manage-environment-variables-in-windows-xp How To Manage Environment Variables in Windows XP 

https://www.chem.gla.ac.uk/~louis/software/faq/q1.html Setting Environment variables, Louis J. Farrugia 

## 3.6.2 Finding the Python executable 

Changed in version 3.5. 

Besides using the automatically created start menu entry for the Python interpreter, you might want to start Python in the command prompt. The installer has an option to set that up for you. 

On the first page of the installer, an option labelled “Add Python to PATH” may be selected to have the installer add the install location into the$_{PATH}$ . The location of the$_{Scripts\}$ folder is also added. This allows you to type $_{python}$to run the interpreter, and $_{pip}$for the package installer. Thus, you can also execute your scripts with command line options, see Command line documentation. 

If you don’t enable this option at install time, you can always re-run the installer, select Modify, and enable it. Alterna- tively, you can manually modify the$_{PATH}$ using the directions in Excursus: Setting environment variables . You need to set your$_{PATH}$ environment variable to include the directory of your Python installation, delimited by a semicolon from other entries. An example variable could look like this (assuming the first two entries already existed): 

C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Python 3.9 

