python运行空白,为什么运行python可执行文件后终端空白?

I added the hashbang line at the beginning of the python script (#!/usr/bin/python) and gave it executable privileges via chmod +x file.py command but after clicking on the module to run it, the terminal pops up but is blank.

Would it have something to do with the python interpreter possibly not being in the specified path?

解决方案

It would appear that that is not a valid shebang.

Try #!/usr/bin/python

(Note the exclaimation after the hash mark.)

Edit in response to comments from OP:

So, based on your comments about clicking the icon in a file manager and the platform being LXDE, it looks like in that use case it ends up calling into the g_app_info_create_from_commandline function from the GAppInfo library, which appears to be a whole layer for storing "application information and launch contexts".

Before that, it ends up bitwise-OR'ing in the G_APP_INFO_CREATE_NEEDS_TERMINAL flag into the flags field that it passes off to fm_app_info_create_from_commandline in the fm-file-launcher.c code.

So, it looks like double-clicking on the file is doing a ton of extra stuff before eventually running it in a terminal, and it would appear that that extra stuff (additional context, abstracted out via other libraries and layers, etc.) is what's causing the issue.

If the feature is really supposed to truly launch things in a terminal "normally", then I would regard it as a bug in the fm-file-launcher.c code or perhaps in the GAppInfo code itself.

I'm not sure the developers would necessarily agree -- it will depend on what exactly is going on under the hood and what they intended that feature to be exactly. If you really want to be able to do this (I'm not sure I really get the benefit over simply using the ./file.py method directly in a terminal window), I would recommend filing a bug against the fm-file-launcher.c code. That is part of the libfm project, and it appears they don't track issues via their github page, but rather, their SourceForge page, according to their forum.

In short, double-clicking on the icon in the file manager and choosing to launch it in the terminal vs. actually launching it in a terminal are very, very different things, even if the former is meant to essentially function like the latter.

As a side note, I tried doing this in Nautilus (I use Ubuntu), and its behavior for that use case is to just automatically assume it's a text file and not an executable and load it into my default text editor.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值