ImportError: No module named gi.repository

自古美人都是妖i 提交于 2019-12-07 01:46:59

问题


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?


回答1:


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.




回答2:


@hob's answer for Anaconda didn't work for me, but conda install -c conda-forge pygobject did.




回答3:


Anaconda usually has python package binaries that will work with your platform (Mac or older Ubuntu). According to @Abhijit you need pygobject. It works a lot like pip:

conda install -c auto pygobject



回答4:


You need to install pygobject, pygobject3(3 comes from the gtk version, not python).

If you're on Mac:

  • ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null Install the latest version of homebrew
  • brew install pygobject Install pyobject
  • brew install pygobject3 Install pyobject3
  • mkdir -p /Users/abhijit/Library/Python/2.7/lib/python/site-packages Check and build the sitepath directory if it doesn't exist
  • echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/abhijit/Library/Python/2.7/lib/python/site-packages/homebrew.pth Create a shortcut in your python Site-packages to your homebrew path



回答5:


Try to fix it by installing PyGObject:

$ sudo apt install python3-gi  # On Ubunto
$ sudo yum install python36-gobject.x86_64 # OR on CentOS / RHEL
$ pip3 install PyGObject # Or directly with pip 


来源:https://stackoverflow.com/questions/23546630/importerror-no-module-named-gi-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!