[MacPorts] #50536: py27-gobject3 @3.18.2_0 "Cannot import GtK"

MacPorts noreply at macports.org
Sat Feb 6 11:31:19 PST 2016


#50536: py27-gobject3 @3.18.2_0 "Cannot import GtK"
--------------------------+--------------------------------
  Reporter:  nek2626@…    |      Owner:  macports-tickets@…
      Type:  defect       |     Status:  new
  Priority:  Normal       |  Milestone:
 Component:  ports        |    Version:  2.3.4
Resolution:               |   Keywords:
      Port:  py-gobject3  |
--------------------------+--------------------------------

Comment (by devans@…):

 Summarizing from above you need to make sure that you are not using Mac OS
 X system python (which goes not have `gi`, etc installed) but instead are
 using MacPorts python27 (which is where `py27-gobject3` installs `gi`).
 It is also true that you need `gtk3` installed if you wish to import `Gtk`
 and/or `Gdk`.

 You can make `python27` your default `python` (the one that is invoked
 when you type `python` and/or `python2`) by following the instructions
 that it suggests when installing `python27`:
 {{{
 $ port notes python27
 python27 has the following notes:
   To make this the default Python or Python 2 (i.e., the version run by
 the 'python' or 'python2'
   commands), run one or both of:

       sudo port select --set python python27
       sudo port select --set python2 python27
 }}}

 Assuming neither `py27-gobject3` nor `gtk3` are installed, the following
 sequence of commands works for me:
 {{{
 $ sudo port install py27-gobject3 gtk3
 $ sudo port select --set python python27
 Selecting 'python27' for 'python' succeeded. 'python27' is now active.
 $ python
 Python 2.7.11 (default, Dec  5 2015, 23:52:42)
 [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import gi
 >>> gi.require_version('Gdk', '3.0')
 >>> gi.require_version('Gtk', '3.0')
 >>> from gi.repository import Gdk, GObject, Gtk
 >>>
 }}}

 Note that, as of `py27-gobject3 3.18.0`, use of
 {{{
 >>> gi.require_version('Gdk', '3.0')
 >>> gi.require_version('Gtk', '3.0')
 }}}

 is necessary to avoid warning messages similar to the following:
 {{{
 >>> from gi.repository import Gtk, GObject, Gdk
 >>> __main__:1: PyGIWarning: Gtk was imported without specifying a version
 first. Use gi.require_version('Gtk', '3.0') before import to ensure that
 the right version gets loaded.
 >>>
 }}}

 Hope this helps

-- 
Ticket URL: <https://trac.macports.org/ticket/50536#comment:4>
MacPorts <https://www.macports.org/>
Ports system for OS X


More information about the macports-tickets mailing list