ImportError: No module named gi.repository
Asked Answered
H

8

15

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?

Heartbeat answered 8/5, 2014 at 15:50 Comment(0)
H
10

Try to fix it by installing 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  
Holotype answered 4/7, 2019 at 9:2 Comment(0)
B
4

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

Brindled answered 1/10, 2018 at 1:3 Comment(1)
You're right. Doesn't look like conda supports -c auto anymore -c conda-forge is the right channel, if you don't already have it set up in your conda config.Soso
K
4
sudo apt-get install -y python-gobject

Fixed it for me on Ubuntu 18.04.

Krever answered 12/4, 2020 at 15:10 Comment(0)
S
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
Soso answered 5/7, 2018 at 18:59 Comment(0)
A
2

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
Atp answered 7/9, 2017 at 15:8 Comment(0)
A
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.

Autotoxin answered 8/5, 2014 at 23:29 Comment(0)
I
1

This works for me (Ubuntu 20.04 LTS):

sudo apt reinstall python3-gi

Ionia answered 27/11, 2021 at 8:47 Comment(0)
B
0

very simple. open /usr/bin/gnome-terminal,you can see the interpreter is python3:

#!/usr/bin/python3

Change the path of the interpreter to python3.5:

#!/usr/bin/python3.5

Fixed it for me on Ubuntu 16.04.

Boatman answered 8/2, 2022 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.