如何运行Python程序? [英] How do I run a Python program?

查看:204
本文介绍了如何运行Python程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我现在正在使用IDLE,但它不会使用,因为您一次只能运行几行。

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

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

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

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

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

我正在使用Windows 7和Komodo Edit 5作为我的IDE。在Komodo中按F5不会做任何事情。

I'm using Windows 7, and Komodo Edit 5 as my IDE. Pressing F5 in Komodo doesn't do anythin at all.

推荐答案

我很高兴你问!我正在努力解释这个事情,在我们的wikibook (显然是不完整的)。我们正在和Python新手合作,不得不通过正确的方式帮助您!

I'm very glad you asked! I was just working on explaining this very thing in our wikibook (which is obviously incomplete). We're working with Python novices, and had to help a few through exactly what you're asking!

Windows中的命令行Python:


  1. 在您的编辑器中使用保存或另存为将您的python代码文件保存在某处。让我们把它称为'first.py'在某些文件夹中,如桌面上的pyscripts。

  1. Save your python code file somewhere, using "Save" or "Save as" in your editor. Lets call it 'first.py' in some folder, like "pyscripts" that you make on your Desktop.

打开提示(Windows的cmdshell,它是一个到计算机的文本界面):

Open a prompt (a Windows 'cmd' shell that is a text interface into the computer):

start> run>cmd(在小盒子里)。好。

start > run > "cmd" (in the little box). OK.

导航到您的python文件的位置,使用命令'cd'(更改目录)和'dir'(以显示目录中的文件,以验证你的头)。对于我们的例子,

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). For our example something like,

> cd C:\Documents and Settings\Gregg\Desktop\pyscripts

> cd C:\Documents and Settings\Gregg\Desktop\pyscripts

尝试:

> python first.py

> python first.py

如果您收到以下消息:


'python'不被识别为
内部或外部命令,可操作的
程序或批处理文件。

'python' is not recognized as an internal or external command, operable program or batch file.

然后 python / em>程序,可以将Python转换为计算机指令)不在您的路径上(请参阅将Python放在您的路径中)。然后尝试像这样调用它(假设Python2.6安装在通常的位置):

then python (the interpreter program that can translate Python into 'computer instructions') isn't on your path (see Putting Python in Your Path below). Then try calling it like this (assuming Python2.6, installed in the usual location):

> C:\Python26\python.exe first.py

> C:\Python26\python.exe first.py

(高级用户:而不是first.py,您可以写出first.py的完整路径C:\Documents和Settings\Gregg\Desktop\pyscripts\\ \\ 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)

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

在Windows中:

控制面板>系统>高级> |环境变量| >系统变量 - >路径

control panel > system > advanced > |Environmental Variables| > system variables -> Path

这需要包括:C:\Python26; (或同等学历)。如果你把它放在前面,
将是第一个看。您也可以在最后添加它,这可能是更为严重的。

this needs to include: 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.

然后重新启动您的提示,然后尝试键入python。如果一切正常,你应该
得到一个>>>提示。

Then restart your prompt, and try typing 'python'. If it all worked, you should get a ">>>" prompt.

这篇关于如何运行Python程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆