Python adds environment variables

Today I have nothing to do but play around with python. I used to play it under windows and there was no problem.

Today I wanted to run python in a dos window, but found that it couldn't run. And it can be run in the python installation directory, so I know that I did not choose to add environment variables when installing python. I still have a certain understanding of Windows, so I manually added environment variables. However, after struggling for a long time and browsing online for a long time, all the methods were not easy to use. I will not list the specific methods one by one. Just tell me the fundamental solution. This method was also summarized after I uninstalled python and reinstalled it and compared the environment variables. It is guaranteed to be easy to use.
Enter the environment variable settings.
Right click on My Computer - Properties, see the picture below.

After clicking " Advanced System Settings " in the red box on the right, see the picture below.

 Then click " Environment Variables " in the red box in the picture above. There are several methods to get here. Use whichever one you are comfortable with. You must get here anyway. After clicking it, you will see the picture below:

Create a new user variable, first click position 1 and see the picture below:

Variable name input: PATH
Variable value input:
C:\Users\shi\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\shi\AppData\Local\Programs\Python\Python37\
Note: The above is the path to install python on my computer. It may be different for everyone. It depends on your installation location and cannot be copied and used.
Click on the location in Figure 2 to set the system variables , as shown below.

 The picture above shows the situation after adding environment variables. Click " New " if you haven't joined yet . Enter the following:
%LOCALAPPDATA%\Programs\Python\Python37
Note: The %LOCALAPPDATA% variable above represents the location "C:\Users\shi\AppData\Local". If python is not installed in the directory C:\Users\shi\AppData\Local\Programs\Python\Python37 It cannot be copied and used directly. The specific variable representation is shown below (for reference only, you don’t need to read it):
REM environment variables and corresponding paths 
%ALLUSERSPROFILE% C:\ProgramData 
%APPDATA% C:\Users\username\AppData\Roaming 
%COMMONPROGRAMFILES% C:\Program Files\Common Files 
%COMMONPROGRAMFILES(x86)% C:\Program Files (x86)\Common Files 
%COMSPEC% C:\Windows\System32\cmd.exe 
%HOMEDRIVE% and %SystemDrive% C:\ 
%HOMEPATH% C:\Users\username 
%LOCALAPPDATA% C:\Users\username\ AppData\Local 
%PROGRAMDATA% C:\ProgramData 
%PROGRAMFILES% C:\Program Files 
%PROGRAMFILES(X86)% C:\Program Files (x86) 
%PUBLIC% C:\UsersPublic
%SystemRoot% C:\Windows
%TEMP% and %TMP% C:\Users\username\AppData\LocalTemp 
%USERPROFILE% C:\Users\username 
%WINDIR% C:\Window 
[%systemroot%\Resources] Windows theme directory C:\WINDOWS\ Resources\[%systemroot%\Web\Wallpaper] The wallpaper directory that comes with Windows C:\WINDOWS\Web\Wallpaper
 After setting the variables in positions 1 and 2 above, confirm and close the window, and then open the dos window input window to open python normally.

Off topic:

Many people only set system variables but not user variables . This is what I did at the beginning, and python cannot be enabled. The environment variables you see after entering path in the dos window are as follows:

See the red box above, the system has not translated the variable %LOCALAPPDATA%, but as long as you enter the environment variable settings once, open the system variables, do nothing, and then confirm to exit. Then enter the dos window and enter the path variable, it will become like this:

The system has translated the environment variables, and python can naturally be used. But after the computer restarted it became unusable. So we still need to add user variables.

After my python version 3.7 is installed, I have the following options:

 The red box above means " Cancel path length restriction ". I did not click on it. Python can be used normally after setting it like this.

Guess you like

Origin blog.csdn.net/kim5659/article/details/133356935