由于与GI

时间:2015-09-17 21:14:29

标签: python linux ubuntu terminal gnome

当我运行gnome-terminal时,我收到以下错误:

Traceback (most recent call last):
  File "/usr/bin/gnome-terminal", line 9, in <module>
    from gi.repository import GLib, Gio
  File "/usr/local/lib/python3.4/dist-packages/gi/__init__.py", line 39
    print url

这对我来说很奇怪,因为脚本位于python 3.4安装中,但是调用print就像是python2脚本一样(这就是发生错误的原因)。

我尝试用pip3重新安装包gi,但它继续安装这个看起来像python2脚本的版本。

我的gnome-terminal指向/ usr / bin / gnome-terminal,这是一个以#!/ usr / bin / python3开头的python脚本。

init .py中包含该特定错误的行是:

if __name__ == '__main__':                                                                                                                                                                                                                                                                                      
         try:                                                                                                                                                                                                                                                                                                    
                 url = save_file()                                                                                                                                                                                                                                                                               
                 print url                                                                                                                                                                                                                                                                                   
         except GistError as e:                                                                                                                                                                                                                                                                                  
                 print e.value     

这表明可以快速修复:将括号放在这两条打印行中。

  File "/usr/bin/gnome-terminal", line 9, in <module>
    from gi.repository import GLib, Gio
ImportError: No module named 'gi.repository'

这很奇怪。

这必须在/ usr / bin / python3上运行,因为这就是/ usr / bin / gnome-terminal上的shebang。

/ usr / bin上的

python3实际上是python3.4的链接,它是一个二进制文件。

然后我运行pip3 install gi,我得到以下输出,告诉我实际安装了gi。

Requirement already satisfied (use --upgrade to upgrade): gi in /usr/local/lib/python3.4/dist-packages
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/lib/python3/dist-packages (from gi)

现在我没有想法。

这是在我尝试从https://github.com/Pumubuntu/Pumubuntu安装Pumubuntu之后开始的。

在主脚本文件中,它说:

import sys
if len(sys.argv) == 1:
    print('Importing Python modules. If one is missing get it with:\n'
          '  "sudo apt-get install python-..." or\n'
          '  "sudo apt-get install girX.Y-..." for gi.repository imports.')

所以我认为我必须输入这些命令。这肯定打破了我的gir装置(gir)。

有人能帮助我吗?

6 个答案:

答案 0 :(得分:11)

我发现修复此错误的另一种方法是修改位于gnome-terminal的{​​{1}}脚本并将环境(脚本的第一行)从/usr/bin/更改为{{1如前面的答案中所述,Github命令行用于Python 2,从Python 3切换到Python 2。

因此,按下超级键(左下方Alt键旁边的键)或按 Alt + F2 并输入{打开#!/usr/bin/python3 {1}}搜索备用终端并单击它以运行。接下来,键入#!/usr/bin/python,按 ENTER 并按照上述编辑第一行。这不是最好的解决方案,因为您不必编辑脚本,但它对我有用,并且不需要卸载任何内容。

更新

最新版本需要Python 3,所以Jon M.在他的评论中指出,更改文件的第一行以使用Python 3.5:

xterm

答案 1 :(得分:7)

在Python 3.5中,我这样做:

  1. sudo vim /usr/bin/gnome-terminal
  2. 将第一行从#!/usr/bin/python修改为#!/usr/bin/python3.5
  3. 这解决了我的问题!

答案 2 :(得分:6)

这是一个老问题,但这是第一次谷歌热播,应该回答。

错误是由 python3 上安装 gi 包引起的。
对于 python2 ,它是 GIST Github命令行的包。与gnome对象或gnome内省相关的。 在这里访问它: python gi on package index

它会导致命名冲突与gi.repository,而不是在你的python dist-packages中查找gir,系统__init__ gi包。因此错误显示

ImportError: No module named 'gi.repository'

卸载该程序包将解决该错误。此外,如果您正在寻找一个大佬,请尝试defunkt gist

答案 3 :(得分:4)

在将python3.5更新为python3.6之后,我也遇到了这个问题

这不是更好的方法,但是可以正常工作。

由于_gi_cairo导致出现此问题。我通过以下代码解决了

@Component
@EndpointWebExtension(endpoint = HealthEndpoint.class)
public class HealthEndpointWebExtension {

    private HealthEndpoint healthEndpoint;
    private HealthStatusHttpMapper statusHttpMapper;

    // Constructor

    @ReadOperation
    public WebEndpointResponse<Health> health() {
        Health health = this.healthEndpoint.health();
        Integer status = this.statusHttpMapper.mapStatus(health.getStatus());
        // log here depending on health status.
        return new WebEndpointResponse<>(health, status);
    }
}

答案 4 :(得分:0)

在Linux(RHEL 7.6)上使用 / usr / bin / chrome-gnome-shell 脚本发生在我身上:

Traceback (most recent call last):
Traceback (most recent call last):
  File "/usr/bin/chrome-gnome-shell", line 16, in <module>
    from gi.repository import GLib, Gio
ModuleNotFoundError: No module named 'gi'

要修复此问题,我必须安装PyGObject

$ sudo yum install python36-gobject.x86_64
# or directly with pip: pip3 install PyGObject

安装完成后,运行脚本没有显示错误。

答案 5 :(得分:0)

更改 Python 3 版本会导致不止 gnome-terminal 无法启动,因为 Python 3 对于许多组件的运行至关重要。当您安装较新版本的 Python 时,并非所有组件所需的所有包都为新 Python 安装;在 gnome-terminal 的情况下是 gi,在其他应用程序的情况下还有其他应用程序。所以升级 Python 3 时要非常小心。

使用 update-alternative 选择以前的 Python 版本会起作用,因为它会将 python3 替代品指向安装了 gi 的正确版本。如果不需要配置,请尝试将您的 2 个版本的 python 安装到 update-alternatives 并选择以前的版本。