I'm very glad you asked!
(你问我很高兴!)
I was just working on explaining this very thing in our wikibook (which is obviously incomplete). (我正在努力在我们的wikibook中解释这个问题(这显然是不完整的)。)
We're working with Python novices, and had to help a few through exactly what you're asking! (我们正在与Python新手合作,并且必须通过您正在询问的内容帮助我们!)
Command-line Python in Windows:
(Windows中的命令行Python:)
Save your python code file somewhere, using "Save" or "Save as" in your editor.
(使用编辑器中的“保存”或“另存为”将python代码文件保存到某处。)
Lets call it 'first.py' in some folder, like "pyscripts" that you make on your Desktop. (让我们在某个文件夹中将其命名为“first.py”,例如您在桌面上创建的“pyscripts”。)
Open a prompt (a Windows 'cmd' shell that is a text interface into the computer):
(打开提示 (Windows'cmd'shell,它是计算机的文本界面):)
start > run > "cmd" (in the little box).
(开始>运行>“cmd”(在小方框中)。)
OK. (好。)
Navigate to where your python file is, using the commands 'cd' (change directory) and 'dir' (to show files in the directory, to verify your head).
(使用命令'cd'(更改目录)和'dir'(显示目录中的文件,验证您的头部)导航到您的python文件所在的位置。)
For our example something like, (对于我们的例子,像,)
> cd C:\Documents and Settings\Gregg\Desktop\pyscripts
(> cd C:\ Documents and Settings \ Gregg \ Desktop \ pyscripts)
try:
(尝试:)
> python first.py
(> python first.py)
If you get this message:
(如果你收到这条消息:)
'python' is not recognized as an internal or external command, operable program or batch file.
('python'不被识别为内部或外部命令,可操作程序或批处理文件。)
then python (the interpreter program that can translate Python into 'computer instructions') isn't on your path (see Putting Python in Your Path below).
(然后python (可以将Python翻译成'计算机指令'的解释程序)不在您的路径上(请参阅下面的将Python放入您的路径中)。)
Then try calling it like this (assuming Python2.6, installed in the usual location): (然后尝试这样调用它(假设Python2.6,安装在通常的位置):)
> C:\Python26\python.exe first.py
(> C:\ Python26 \ python.exe first.py)
(Advanced users: instead of first.py, you could write out first.py's full path of C:\Documents and Settings\Gregg\Desktop\pyscripts\first.py)
((高级用户:而不是first.py,你可以写出first.py的C:\ Documents and Settings \ Gregg \ Desktop \ pyscripts \ first.py的完整路径))
Putting Python In Your Path
(把Python放在你的路上)
Windows
(视窗)
In order to run programs, your operating system looks in various places, and tries to match the name of the program / command you typed with some programs along the way.
(为了运行程序,您的操作系统会在不同的位置查找,并尝试在此过程中将您键入的程序/命令的名称与某些程序相匹配。)
In windows:
(在Windows中:)
control panel > system > advanced > |Environmental Variables|
(控制面板>系统>高级> |环境变量|)
> system variables -> Path (>系统变量 - >路径)
this needs to include: C:\Python26;
(这需要包括:C:\ Python26;)
(or equivalent). ((或同等学历)。)
If you put it at the front, it will be the first place looked. (如果你把它放在前面,那将是第一个看的地方。)
You can also add it at the end, which is possibly saner. (您也可以在最后添加它,这可能更安全。)
Then restart your prompt, and try typing 'python'.
(然后重新启动提示,并尝试键入“python”。)
If it all worked, you should get a ">>>" prompt. (如果一切正常,你应该得到一个“>>>”提示符。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…