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

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

问题描述

所以我开始有点像 Python,但我在运行它时遇到了麻烦 erm....哈哈

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 'cmd' shell,它是计算机的文本界面):

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

开始>运行>cmd"(在小框中).行.

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

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

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 SettingsGreggDesktoppyscripts

> cd C:Documents and SettingsGreggDesktoppyscripts

试试:

> python first.py

> python first.py

如果您收到此消息:

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

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

那么 python(可以将 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:Python26python.exe first.py

> C:Python26python.exe first.py

(高级用户:可以不写first.py,而是写出first.py的C:Documents and SettingsGreggDesktoppyscriptsfirst.py的完整路径)

(Advanced users: instead of first.py, you could write out first.py's full path of C:Documents and SettingsGreggDesktoppyscriptsfirst.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.

在窗口中:

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

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天全站免登陆