15

I am installing virt-manager0.10.0 on Mac OS X

First I installed python,libvirt, gtk+3, pygtk, and other dependencies with homebrew

But when I run virt-manager I got this error

from gi.repository import GObject
ImportError: No module named gi.repository

When I run this import in python command line I get same error.but there is no error when I try import gtk

I think the problem is the homebrew pygtk version doesn't use gtk+3 and uses gtk2 and as we can see here gi.repository Windows only gtk+3 use that syntax.

Community
  • 1
  • 1
MKT
  • 655
  • 1
  • 6
  • 18

4 Answers4

27

The gi module is in the pygobject package but if you install this package on OS/X, you won't get the gi module. To really install gi on OS/X you need to install pygobject3 module which may look like it's for Python3 but it's not, the 3 comes from GTK version. So if you're on the OS/X, the simple brew install pygobject3 will do the trick.

kikap
  • 832
  • 11
  • 14
  • 3
    Hi, I am building rednotebook on os x. When I run the 'run' script, I get 'ERROR pygobject could not be imported: "No module named 'gi'". Please install it (python3-gi).' I have executed 'brew install pygobject3', however I still get the same error. I have checked which modules are installed in '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/'. I can't se the gi module. Is the advice still current ? Any other idea on how to proceed ? – stackQA Aug 26 '19 at 06:45
  • @stackQA did you find any solution to install rednotebook on mac? – Fed Nov 23 '21 at 17:23
  • @FedericoCapaldo I did not find a solution to installing rednotebook on a Mac. – stackQA Nov 26 '21 at 20:56
  • Looks like there's something up with brew's python & site-packages. I needed to use the PYTHONPATH env variable as described in [this comment](https://stackoverflow.com/questions/68394880/brew-installed-python3-9-modules-in-site-packages-not-found#comment120908755_68394880), and then `import gi` worked! – Jared Forsyth May 16 '22 at 04:01
4

pyGTK is for GTK 2 only. If you want the python bindings for GTK 3, you need to install pyGObject. See https://stackoverflow.com/a/9672426/518853

Community
  • 1
  • 1
liberforce
  • 11,189
  • 37
  • 48
0

Did you use the built Python or the one that home brew installed to /opt/python/ ? issue which python in your term. Then in python issue import sys; print sys.path.

oz123
  • 27,559
  • 27
  • 125
  • 187
  • which python : /usr/local/bin/python and sys.path :'/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/site-packages/... – MKT Aug 08 '13 at 07:05
  • @MKT, is `/usr/local/bin/` your home brew path? check this guide https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python. I suspect you installed libvirt and gtk using another python. – oz123 Aug 08 '13 at 07:11
  • Yes thats brew path. No I install gtk using brew python. – MKT Aug 08 '13 at 07:23
  • can you post the full list of commands you did as an update to your question? – oz123 Aug 08 '13 at 07:49
0

The python3 bindings for GTK3 can be installed with brew install pygobject3 --with-python3 or brew reinstall pygobject3 --with-python3

Andi
  • 199
  • 2
  • 9
  • 9
    Running `brew reinstall pygobject3 --with-python3` produces a warning: `Warning: pygobject3: this formula has no --with-python3 option so it will be ignored!` – asherbret Sep 28 '18 at 07:17
  • 4
    I tried with brew reinstall pygobject3 --with-python3 and got Error: invalid option: --with-python3 – Biranchi Sep 12 '19 at 08:41