10

I have installed python gtk3 using homebrew but it prints

Warning: gtk+3-3.14.6 already installed

but when i try to import it in python

 from gi.repository import Gtk

it gives the error

ImportError: No module named gi.repository

Please help.

hg8
  • 1,082
  • 2
  • 15
  • 28
Kritesh Semwal
  • 163
  • 1
  • 1
  • 8

3 Answers3

10

When I installed only pygobject3 I got the following error when running a python script:

    gi.require_version('Gtk', '3.0')
  File "/usr/local/lib/python2.7/site-packages/gi/__init__.py", line 102, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available

So it seems to me that you need to install both packages to get gtk3 with python bindings on Mac OS X:

brew install gtk+3 pygobject3
zakx
  • 681
  • 5
  • 17
asmaier
  • 11,132
  • 11
  • 76
  • 103
  • 2
    Just be careful that this will work with Homebrew Python3 only. It's separate from the python.org Python3 (/System/Library ...), if any. – kakyo Aug 18 '19 at 10:22
  • Just went through this - if you want to use anything besides homebrew python3 this won't work. Here's a conda alternative https://stackoverflow.com/a/60701630/5824843 – Hansang Mar 16 '20 at 07:13
3

Python bindings are not provided by GTK+. You need to install pygobject3.

ianml
  • 772
  • 5
  • 9
3

Installing using homebrew worked for me on 10.14:

brew install pygobject3 --with-python@2 gtk+3

References:

https://pygobject.readthedocs.io/en/latest/getting_started.html#macosx-logo-macos

digitalnomd
  • 1,380
  • 12
  • 21
  • 1
    no sure why someone unvote this. the --with-python@2 saved me some months ago. Today --with-pytohn@2 is not working anymore, it seems that the problem has been fixed. – llazzaro May 20 '19 at 00:00