简体   繁体   中英

Why is terminal blank after running python executable?

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.

It could have something to do with the script not actually being set to print anything out. Remember, while all statements get printed output if run directly in the interpreter, for example,

>>> a = 2
>>> a ** a
4

would show in the intrepeter, but you would need a print statement (function in P3k) for the output to be shown if run as a script.

You have to have something to output the items to the terminal like for your file.py:

#!/usr/bin/python

print "test"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM