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.

你可能感兴趣的:(python运行空白)