Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

python - 我如何运行Python程序?(How do I run a Python program?)

So I'm starting like Python a bit, but I'm having trouble erm...running it.

(所以我开始像Python一样,但我遇到麻烦...运行它。)

Lol

(大声笑)

I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time.

(我现在正在使用IDLE,但它没有任何用处,因为你一次只能运行几行。)

I'm also using Komodo Edit to create the actual .py files.

(我也使用Komodo Edit来创建实际的.py文件。)

My question is, how can I run the .py files to test out the actual program?

(我的问题是,如何运行.py文件来测试实际的程序?)

I'm using Windows 7, and Komodo Edit 5 as my IDE.

(我正在使用Windows 7和Komodo Edit 5作为我的IDE。)

Pressing F5 in Komodo doesn't do anythin at all.

(在Komodo按F5并没有做任何事情。)

替代文字

  ask by Sergio Tapia translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:)

  1. 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”。)

  2. 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.

    (好。)

  3. 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)

  4. 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.

(如果一切正常,你应该得到一个“>>>”提示符。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...