为什么在运行python可执行文件后终端为空白? [英] Why is terminal blank after running python executable?

查看:619
本文介绍了为什么在运行python可执行文件后终端为空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python脚本(#!/usr/bin/python)的开头添加了 hashbang 行,并通过chmod +x file.py命令为其赋予了可执行特权,但是在单击模块以运行它后,终端弹出向上但为空白.

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.

是否可能与不在指定路径中的python解释器有关?

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

推荐答案

这似乎不是有效的 shebang .

尝试#!/usr/bin/python

(请注意井号后的惊叹号.)

(Note the exclaimation after the hash mark.)

根据OP的评论进行

因此,基于您对单击文件管理器中的图标以及平台为 LXDE 的评论,在这种情况下,它最终会从<一个href ="https://developer.gnome.org/gio/2.35/GAppInfo.html" rel ="nofollow"> GAppInfo 库,该库似乎是用于存储应用程序信息和启动上下文的完整层" .

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".

在此之前,它会在G_APP_INFO_CREATE_NEEDS_TERMINAL标志中的flags字段中按位或运算,然后在fm_app_info_create_from_commandline /libfm/blob/0ad53a6b350f66bde58011115b915264d53eab9f/src/base/fm-file-launcher.c"rel =" nofollow> fm-file-launcher.c 代码.

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.

如果该功能确实应该正常"地在终端中真正启动,那么我会将其视为 fm-file-launcher.c 代码或 GAppInfo 代码本身.

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.

我不确定开发人员是否一定会同意-这将取决于引擎盖下到底发生了什么,以及他们希望该功能到底是什么.如果您确实希望能够做到这一点(我不确定我是否真的能从直接在终端窗口中直接使用./file.py方法获得收益),我建议针对 fm文件提交一个错误-launcher.c 代码.这是 libfm 项目的一部分,根据他们的论坛.

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.

作为旁注,我尝试在 Nautilus 中进行此操作(我使用 Ubuntu ),并且在该用例中,其行为只是自动假定它是文本文件而不是可执行文件,然后将其加载到我的默认文本编辑器中.

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可执行文件后终端为空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆