I just learned python not long ago, and I was reading "automate the boring stuff with python", but I still didn't understand this part. The relevant passages in the book are shown in the figure.

So what is going to happen?
What if pw.py in the previous picture does not exist on the C drive? For example, it exists in the pythonCodes folder of the D drive? I still don’t understand the second picture...Does that file need to be in the same folder as where python is installed?
Thank you, Taoist priests...
In fact, it just allows you to configure environment variables. If you have a project called
pythonCodes, then you have to set yourpythonCodesinSystem Properties->Environment Variables->pathAdd the absolute path. In this case, if you write a python script inpythonCodes, such ascommand.py, you can directly run it throughwin+R, and then entercommand.pyto run it directly...However, I don’t recommend doing this, because it will develop bad habits and rely heavily on environment variables. Moreover, once the project changes location, the environment variables will have to be changed. Instead of doing this, it is better to directly select a working path. Then just develop on it!Environment variables only need to be set in the python program
What it means is to create a
pw.batfile and register the directory where thispw.batis located into the global%PATH%environment variable.pw.batThe content isWhere
eeeeeerepresents the path of thepython.exeexecutable file. This book usespy.exe, but during actual installation, the default Python executable file for most users ispython.exe. If thispython.exeis not registered globally (that is to say, it is not in the%PATH%environment variable, and the command line directly runspythonand cannot be accessed), then theeeeeepart here needs to usepython The full path of .exe.Secondly,
xxxxxis the path to the.pyfile. This method is to run a python file permanently, and only enter the parameters that need to be passed into the python file after Win+R. And if you need to enter the Python path in Win+R, you should omit thexxxxxpart.Then, since the path of
pw.batis registered to the%PATH%environment variable, you can call the script by runningpw python script pathdirectly from Win+R.It doesn’t matter where pw.py is placed, because for these paths, if the directory has been registered to the
%PATH%environment variable, you can directly write the file name. If the directory has not been registered to%PATHEnvironment variables, you must write the entire path, nothing more, the same is true for the previouspy.exe.