如何在没有 Komodo -ide 的情况下执行 Python 代码?
我在没有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果某些东西在
ipython
中不起作用,请尝试真正的 Python 解释器(只需python
); ipython 存在已知的错误,并且已知在真实解释器中工作的代码经常会失败。在类 UNIX 平台上,您的脚本应以 shebang 开头,即类似以下的行:
应该是第一行(并且应该有标准的 UNIX 行结尾)。 这告诉操作系统使用
PATH
中找到的第一个 python 解释器执行您的代码,假设您的脚本具有可执行权限集并作为程序调用。另一种选择是手动启动程序 - 按照以下示例:
...或者使用特定版本的解释器(如果安装了多个解释器):
If something doesn't work in
ipython
, try the real Python interpreter (justpython
);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:
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:
...or, to use a specific version of the interpreter (if more than one is installed):