如何在没有Komodo -ide的情况下执行Python代码?

时间:2021-01-17 20:41:43

I do that without the IDE:

我没有IDE就这样做:

$ ipython
$ edit file.py
$ :x (save and close)

It executes Python code, but not the one, where I use Pygame. It gives:

它执行Python代码,但不是我使用Pygame的代码。它给:

WARNING: Failure executing file:

警告:执行文件失败:

In the IDE, my code executes.

在IDE中,我的代码执行。

1 个解决方案

#1


If something doesn't work in ipython, try the real Python interpreter (just python); ipython has known bugs, and not infrequently code known to work in the real interpreter fails there.

如果某些内容在ipython中不起作用,请尝试使用真正的Python解释器(只需python); ipython已经知道了bug,而且很少有人知道在真正的解释器中工作的代码会失败。

On UNIXlike platforms, your script should start with a shebang -- that is, a line like the following:

在类UNIX平台上,您的脚本应该以shebang开头 - 也就是说,如下所示:

#!/usr/bin/env python

should be the very first line (and should have a standard UNIX line ending). This tells the operating system to execute your code with the first python interpreter found in the PATH, presuming that your script has executable permission set and is invoked as a program.

应该是第一行(并且应该有一个标准的UNIX行结束)。这告诉操作系统使用PATH中的第一个python解释器执行代码,假设您的脚本具有可执行权限集并作为程序调用。

The other option is to start the program manually -- as per the following example:

另一种选择是手动启动程序 - 根据以下示例:

$ python yourprogram.py

...or, to use a specific version of the interpreter (if more than one is installed):

...或者,使用特定版本的解释器(如果安装了多个):

$ python2.5 yourprogram.py

#1


If something doesn't work in ipython, try the real Python interpreter (just python); ipython has known bugs, and not infrequently code known to work in the real interpreter fails there.

如果某些内容在ipython中不起作用,请尝试使用真正的Python解释器(只需python); ipython已经知道了bug,而且很少有人知道在真正的解释器中工作的代码会失败。

On UNIXlike platforms, your script should start with a shebang -- that is, a line like the following:

在类UNIX平台上,您的脚本应该以shebang开头 - 也就是说,如下所示:

#!/usr/bin/env python

should be the very first line (and should have a standard UNIX line ending). This tells the operating system to execute your code with the first python interpreter found in the PATH, presuming that your script has executable permission set and is invoked as a program.

应该是第一行(并且应该有一个标准的UNIX行结束)。这告诉操作系统使用PATH中的第一个python解释器执行代码,假设您的脚本具有可执行权限集并作为程序调用。

The other option is to start the program manually -- as per the following example:

另一种选择是手动启动程序 - 根据以下示例:

$ python yourprogram.py

...or, to use a specific version of the interpreter (if more than one is installed):

...或者,使用特定版本的解释器(如果安装了多个):

$ python2.5 yourprogram.py