13

I'm trying to launch python script on Ubuntu 10.04:

from gi.repository import Nautilus, GObject

It doesn't work:

Traceback (most recent call last):
  File "script.py", line 1, in <module>
    from gi.repository import Nautilus, GObject
   ImportError: No module named gi.repository

I installed python-gobject-dev, python-gobject, python-nautilus, but it didn't help. Has anyone had this problem?

4

8 回答 8

9

尝试通过安装PyGObject来修复它:

# With Apt on Ubuntu:
$ sudo apt install python3-gi

# With Yum on CentOS / RHEL:
$ sudo yum install python36-gobject.x86_64 

# Or directly with Pip:
$ pip3 install PyGObject  
于 2019-07-04T09:02:27.293 回答
4
sudo apt-get install -y python-gobject

在 Ubuntu 18.04 上为我修复了它。

于 2020-04-12T15:10:44.980 回答
3

@hob 对 Anaconda 的回答对我不起作用,但conda install -c conda-forge pygobject确实如此。

于 2018-10-01T01:03:12.597 回答
2

10.04? That's pre-GNOME 3, so the preferred Python bindings were based on PyGTK, not PyGObject. You need to either use the (obsolete) PyGTK bindings or upgrade to a newer OS.

于 2014-05-08T23:29:08.537 回答
2

Anaconda通常具有适用于您的平台(Mac 或旧版 Ubuntu)的 python 软件包二进制文件。根据@Abhijit,您需要pygobject. 它的工作原理很像pip

conda install -c auto pygobject
于 2018-07-05T18:59:37.287 回答
1

需要安装pygobject,pygobject3(3来自gtk版本,不是python)。

如果您使用的是 Mac:

  • ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null安装最新版本的自制软件
  • brew install pygobject安装 pyobject
  • brew install pygobject3安装 pyobject3
  • mkdir -p /Users/abhijit/Library/Python/2.7/lib/python/site-packages如果站点路径目录不存在,请检查并构建它
  • echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/abhijit/Library/Python/2.7/lib/python/site-packages/homebrew.pth在你的 python Site-packages 中创建一个快捷方式到你的 homebrew 路径
于 2017-09-07T15:08:20.730 回答
0

很简单。打开/usr/bin/gnome-terminal,可以看到解释器是python3:

#!/usr/bin/python3

将解释器的路径改为python3.5:

#!/usr/bin/python3.5

在 Ubuntu 16.04 上为我修复了它。

于 2022-02-08T09:56:12.850 回答
0

这对我有用(Ubuntu 20.04 LTS):

sudo apt reinstall python3-gi

于 2021-11-27T08:47:33.723 回答