python 文件可以在命令提示符下执行,而不管您安装 Python 程序的驱动器是什么?

Can python file be executed in Command Prompt regardless the drive where you installed Python program?

如果我将 Python 程序安装在我的 E 盘而不是 C 盘,我是否必须在我安装 python 程序的同一驱动器中执行 python 文件命令提示符?

比如我在E盘安装了Python程序。我只能通过以下命令执行python个文件?

E:\python34\python filename.py

没有

C:\python34\python filename.py

E:\others_direactory\python filename.py

所以,我总是需要告诉计算机使用Python程序来执行python.py,否则它会警告"XXX is not recognized as an internal or external command, operable program or batch file"。

是吗?

谢谢

这个post应该解释如何设置你的环境变量。

How to add to the pythonpath in windows 7?

是的,您总是必须告诉计算机使用 python 可执行文件来执行 python 程序。安装到 C: 或 E: 驱动器都没有关系,您总是必须通过指定 python 可执行文件开始。你的程序运行只是传递给它的一个参数。

您可以按照@jake-griffin 的建议并将位置添加到您的系统 Path 变量,这样您只需键入 python 而不是它的整个路径,从而减轻痛苦。