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

发布于 2024-07-13 10:20:42 字数 228 浏览 4 评论 0原文

我在没有 IDE 的情况下执行此操作:

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

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

警告:执行文件失败:

在 IDE 中,我的代码执行。

I do that without the IDE:

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

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

WARNING: Failure executing file:

In the IDE, my code executes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里兽 2024-07-20 10:20:42

如果某些东西在 ipython 中不起作用,请尝试真正的 Python 解释器(只需 python); ipython 存在已知的错误,并且已知在真实解释器中工作的代码经常会失败。

在类 UNIX 平台上,您的脚本应以 shebang 开头,即类似以下的行:

#!/usr/bin/env python

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

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

$ python yourprogram.py

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

$ python2.5 yourprogram.py

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.

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

#!/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.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文