WesR
WesR

Reputation: 1512

No module named 'gi' in Python GTK+ 3 Tutorial Hello World

https://python-gtk-3-tutorial.readthedocs.io/en/latest/install.html

I have been trying to follow this tutorial but can't seem to get things installed right. The tutorial example and result is at the bottom. It seems clear, though, that I am failing to follow the instructions to install the needed modules on MacOS Mojave.

The steps I have followed are:

brew install GTK+3
brew install gobject-introspection
brew install PyGObject
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 \
    /Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py

Although this is not in the tutorial I tried pip install PyGObject and got a long error message:

Command "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/vf/x732mfwj4nvf5g_mntsyw97h0000gp/T/pip-install-xfgd22p9/PyGObject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/vf/x732mfwj4nvf5g_mntsyw97h0000gp/T/pip-record-3tko684k/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/vf/x732mfwj4nvf5g_mntsyw97h0000gp/T/pip-install-xfgd22p9/PyGObject/

The error message is:

3.7.1 (default, Nov 28 2018, 11:51:54) 
Traceback (most recent call last):
[Clang 10.0.0 (clang-1000.11.45.5)]
  File "/Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py", line 5, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

import sys
print(sys.version)

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtkwindow
window = Gtk.Window(title="Hello World")

window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()

The error message is:

3.7.1 (default, Nov 28 2018, 11:51:54) 
Traceback (most recent call last):
[Clang 10.0.0 (clang-1000.11.45.5)]
  File "/Users/Wes/Dropbox/Programming/Python/glade_againnn/tryit.py", line 5, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

I have tried these steps in a virtualenv and then again with no virtualenv active.

What should I try next?

Upvotes: 3

Views: 5230

Answers (1)

l&#39;L&#39;l
l&#39;L&#39;l

Reputation: 47159

You have two versions of Python installed (3.6 and 3.7.1). The one GTK is using is:

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

You’ll need to install GTK for Python 3.7.1 if that’s the one you want to use it with.

Upvotes: 6

Related Questions