如何从 Windows cmd 运行 Python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15170761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run Python from Windows cmd
提问by user1210233
I am trying to run a python program in Windows with a call like this:
我试图在 Windows 中运行一个 python 程序,调用如下:
python pacman.py
I have many such calls to the python program. I want to run it from windows command line. When I run this in Ubuntu it works well but when I try it in Windows, I get the following error:
我对 python 程序有很多这样的调用。我想从 Windows 命令行运行它。当我在 Ubuntu 中运行它时它运行良好,但是当我在 Windows 中尝试它时,我收到以下错误:
'python' is not recognized as an internal or external command, operable program or batch file.
How can I run these python programs from Windows cmd?
如何从 Windows cmd 运行这些 python 程序?
回答by Matt
You need to modify the Windows %PATH% environment variable. Under My Computer ? Properties ? Advanced ? Environment Variables, you should modify the %PATH% variable to include your Python directory, i.e. C:\Python26.
您需要修改 Windows %PATH% 环境变量。在我的电脑下?特性 ?先进的 ?环境变量,您应该修改 %PATH% 变量以包含您的 Python 目录,即 C:\Python26。
See: http://docs.python.org/2/using/windows.html#excursus-setting-environment-variables
请参阅:http: //docs.python.org/2/using/windows.html#excursus-setting-environment-variables
回答by Norton Penguinion
That means Python Path isn't declared. Try this:
这意味着未声明 Python 路径。尝试这个:
cd --> to pacman.py dir
C:\PythonVersion\python.exe pacman.py
回答by Wolfer
Simply calling pacman.pyfrom the command line is enough if your windows is set to open .pyfiles with python.exe. Which is easily done through the file manager. (And gets set by default when installing python.)
简单地调用pacman.py,如果你的Windows设置为打开命令行是不够.py用的文件python.exe。这很容易通过文件管理器完成。(并且在安装 python 时默认设置。)
回答by Boshika Tara
Try using this, dir C:\py*, this should give you a message like this "Volume in Drive C: Windows version--- Volume Serial number Directory of C: and a Path to Python, where it is installed on your computer", if you get this you are good to go...
尝试使用这个,dir C:\py*,这应该会给你一条这样的消息“驱动器 C 中的卷:Windows 版本---卷序列号 C: 的目录和 Python 的路径,它安装在你的计算机上“,如果你得到这个,你就可以走了......

