You are not logged in.
Pages: 1
Topic closed
I was trying to work with gtk+3 in python. This http://python-gtk-3-tutorial.readthedoc … l.html#id2 page says I need Pygobject. I installed it.
Sample code from http://python-gtk-3-tutorial.readthedoc … ction.html page has gi.repository as module to be imported.
When I try to run it, i get 'No module named gi.repository'.
Edit: Also installed python-gobject . Still get same result.
Last edited by bibek22 (2015-11-08 15:50:32)
Offline
Take a look here https://bbs.archlinux.org/viewtopic.php?id=203480. You should also provide more information on the issue, in particular: are you using python3 or python2? How did you install pygobject and python-gobject?
Can you also post the output of the following commands?
$ which python
$ pacman -Qikk python-gobject python
$ python -c "import gi; print(gi.__spec__)"
$ python -c "import gi; print(gi.__dict__)"
NOTE: replace python with python2 in the above commands if you are using python2.
--edit:
Well, after reading your original post in the email notification (that was sent to me since I'm subscribed to this sub-forum), it seems to me that you didn't use pacman to install python-gobject, but you tried to use Jhbuild instead (whatever it is). If so, please undo everything you've done and install python-gobject using pacman: that's all you need to run the sample gtk3 code.
Last edited by mauritiusdadd (2015-11-08 09:57:14)
Offline
$ which python
/usr/bin/python3
$ pacman -Qikk python-gobject python
Name : python-gobject
Version : 3.18.2-1
Description : Python 3 bindings for GObject
Architecture : x86_64
URL : https://live.gnome.org/PyGObject
Licenses : LGPL
Groups : None
Provides : None
Depends On : gobject-introspection-runtime
pygobject-devel=3.18.2 python cairo
Optional Deps : None
Required By : None
Optional For : redshift
Conflicts With : None
Replaces : None
Installed Size : 1054.00 KiB
Packager : Jan Alexander Steffens (heftig)
<jan.steffens@gmail.com>
Build Date : Sat 24 Oct 2015 10:59:45 PM NPT
Install Date : Sun 08 Nov 2015 01:50:02 PM NPT
Install Reason : Explicitly installed
Install Script : No
Validated By : Signature
python-gobject: 92 total files, 0 altered files
Name : python
Version : 3.5.0-2
Description : Next generation of the python high-level
scripting language
Architecture : x86_64
URL : http://www.python.org/
Licenses : custom
Groups : None
Provides : python3
Depends On : expat bzip2 gdbm openssl libffi
zlib
Optional Deps : python-setuptools [installed]
python-pip [installed]
sqlite [installed]
mpdecimal: for decimal
xz: for lzma [installed]
tk: for tkinter
Required By : python-gobject python-gobject2
python-packaging python-pip
python-xdg youtube-dl
Optional For : cairo-dock-plug-ins texlive-core
util-linux
Conflicts With : None
Replaces : python3
Installed Size : 101.14 MiB
Packager : Felix Yan <felixonmars@archlinux.org>
Build Date : Sun 20 Sep 2015 05:33:48 PM NPT
Install Date : Sun 08 Nov 2015 01:44:27 PM NPT
Install Reason : Installed as a dependency for another
package
Install Script : No
Validated By : Signature
python: 6761 total files, 0 altered files
$ python -c "import gi; print(gi.__spec__)"
ModuleSpec(name='gi', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f8b8ce82d30>, origin='/usr/lib/python3.5/site-packages/gi/__init__.py', submodule_search_locations=['/usr/lib/python3.5/site-packages/gi'])
$ python -c "import gi; print(gi.__dict__)"
{'_DummyStaticModule': <class 'gi._DummyStaticModule'>, '_error': <module 'gi._error' from '/usr/lib/python3.5/site-packages/gi/_error.py'>, 'version_info': (3, 18, 2), 'PyGIWarning': <class 'gi.PyGIWarning'>, 'get_required_version': <function get_required_version at 0x7efdda38d620>, 'types': <module 'types' from '/usr/lib/python3.5/types.py'>, '__spec__': ModuleSpec(name='gi', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7efddbb05d30>, origin='/usr/lib/python3.5/site-packages/gi/__init__.py', submodule_search_locations=['/usr/lib/python3.5/site-packages/gi']), '__name__': 'gi', '__path__': ['/usr/lib/python3.5/site-packages/gi'], '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7efddbb05d30>, 'check_version': <function check_version at 0x7efdda38d158>, '__doc__': None, 'os': <module 'os' from '/usr/lib/python3.5/os.py'>, '_gi': <module 'gi._gi' from '/usr/lib/python3.5/site-packages/gi/_gi.cpython-35m-x86_64-linux-gnu.so'>, '__cached__': '/usr/lib/python3.5/site-packages/gi/__pycache__/__init__.cpython-35.pyc', '__version__': '3.18.2', 'sys': <module 'sys' (built-in)>, '__package__': 'gi', '_overridesdir': '/usr/lib/python3.5/site-packages/gi/overrides', 'require_foreign': <function require_foreign at 0x7efdda38d6a8>, '_versions': {}, 'importlib': <module 'importlib' from '/usr/lib/python3.5/importlib/__init__.py'>, '_static_binding_error': 'When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183', 'absolute_import': _Feature((2, 5, 0, 'alpha', 1), (3, 0, 0, 'alpha', 0), 16384), '__file__': '/usr/lib/python3.5/site-packages/gi/__init__.py', 'Repository': <class 'gi.Repository'>, '_gobject': <module '_gobject'>, '_API': <capsule object "gi._API" at 0x7efdda3871e0>, 'PyGIDeprecationWarning': <class 'gi.PyGIDeprecationWarning'>, 'require_version': <function require_version at 0x7efdda38d268>, '__builtins__': {'OSError': <class 'OSError'>, 'dir': <built-in function dir>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'ArithmeticError': <class 'ArithmeticError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'AssertionError': <class 'AssertionError'>, 'ascii': <built-in function ascii>, '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>), 'BlockingIOError': <class 'BlockingIOError'>, 'ImportWarning': <class 'ImportWarning'>, 'callable': <built-in function callable>, 'pow': <built-in function pow>, 'slice': <class 'slice'>, 'UserWarning': <class 'UserWarning'>, 'EOFError': <class 'EOFError'>, 'SyntaxWarning': <class 'SyntaxWarning'>, 'format': <built-in function format>, 'float': <class 'float'>, '__import__': <built-in function __import__>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'divmod': <built-in function divmod>, 'MemoryError': <class 'MemoryError'>, 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more information., 'TypeError': <class 'TypeError'>, 'chr': <built-in function chr>, 'reversed': <class 'reversed'>, 'issubclass': <built-in function issubclass>, 'TimeoutError': <class 'TimeoutError'>, 'hash': <built-in function hash>, 'ChildProcessError': <class 'ChildProcessError'>, 'sorted': <built-in function sorted>, 'iter': <built-in function iter>, 'help': Type help() for interactive help, or help(object) for help about object., 'EnvironmentError': <class 'OSError'>, 'copyright': Copyright (c) 2001-2015 Python Software Foundation.
All Rights Reserved.
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.
Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'bool': <class 'bool'>, 'vars': <built-in function vars>, 'getattr': <built-in function getattr>, 'object': <class 'object'>, 'NotImplemented': NotImplemented, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'frozenset': <class 'frozenset'>, 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, 'IndexError': <class 'IndexError'>, 'SyntaxError': <class 'SyntaxError'>, 'dict': <class 'dict'>, 'globals': <built-in function globals>, '__name__': 'builtins', '__loader__': <class '_frozen_importlib.BuiltinImporter'>, 'NotADirectoryError': <class 'NotADirectoryError'>, 'StopAsyncIteration': <class 'StopAsyncIteration'>, 'repr': <built-in function repr>, 'SystemError': <class 'SystemError'>, 'True': True, 'bytes': <class 'bytes'>, 'int': <class 'int'>, 'InterruptedError': <class 'InterruptedError'>, 'map': <class 'map'>, 'isinstance': <built-in function isinstance>, 'StopIteration': <class 'StopIteration'>, 'property': <class 'property'>, 'hex': <built-in function hex>, 'ResourceWarning': <class 'ResourceWarning'>, 'tuple': <class 'tuple'>, 'Ellipsis': Ellipsis, 'TabError': <class 'TabError'>, 'setattr': <built-in function setattr>, 'any': <built-in function any>, 'classmethod': <class 'classmethod'>, 'enumerate': <class 'enumerate'>, 'id': <built-in function id>, 'IOError': <class 'OSError'>, 'ReferenceError': <class 'ReferenceError'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'UnicodeWarning': <class 'UnicodeWarning'>, 'BufferError': <class 'BufferError'>, 'None': None, 'ValueError': <class 'ValueError'>, 'abs': <built-in function abs>, 'max': <built-in function max>, 'ConnectionError': <class 'ConnectionError'>, 'RuntimeWarning': <class 'RuntimeWarning'>, 'complex': <class 'complex'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, 'compile': <built-in function compile>, 'Exception': <class 'Exception'>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'next': <built-in function next>, 'False': False, 'FloatingPointError': <class 'FloatingPointError'>, '__debug__': True, 'len': <built-in function len>, 'str': <class 'str'>, 'input': <built-in function input>, 'BaseException': <class 'BaseException'>, 'exec': <built-in function exec>, 'min': <built-in function min>, 'AttributeError': <class 'AttributeError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'RuntimeError': <class 'RuntimeError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'PermissionError': <class 'PermissionError'>, 'oct': <built-in function oct>, 'Warning': <class 'Warning'>, 'OverflowError': <class 'OverflowError'>, 'LookupError': <class 'LookupError'>, 'ord': <built-in function ord>, 'hasattr': <built-in function hasattr>, 'bytearray': <class 'bytearray'>, 'open': <built-in function open>, 'eval': <built-in function eval>, 'RecursionError': <class 'RecursionError'>, 'staticmethod': <class 'staticmethod'>, 'IndentationError': <class 'IndentationError'>, 'FileExistsError': <class 'FileExistsError'>, 'GeneratorExit': <class 'GeneratorExit'>, 'delattr': <built-in function delattr>, 'NameError': <class 'NameError'>, 'ImportError': <class 'ImportError'>, '__build_class__': <built-in function __build_class__>, 'zip': <class 'zip'>, '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", 'FileNotFoundError': <class 'FileNotFoundError'>, 'KeyError': <class 'KeyError'>, 'round': <built-in function round>, 'SystemExit': <class 'SystemExit'>, 'memoryview': <class 'memoryview'>, '__package__': '', 'print': <built-in function print>, 'license': Type license() to see the full license text, 'locals': <built-in function locals>, 'super': <class 'super'>, 'type': <class 'type'>, 'filter': <class 'filter'>, 'UnicodeError': <class 'UnicodeError'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'BytesWarning': <class 'BytesWarning'>, 'set': <class 'set'>, 'IsADirectoryError': <class 'IsADirectoryError'>, 'range': <class 'range'>, 'NotImplementedError': <class 'NotImplementedError'>, 'ProcessLookupError': <class 'ProcessLookupError'>, 'bin': <built-in function bin>, 'list': <class 'list'>, 'all': <built-in function all>, 'sum': <built-in function sum>, 'FutureWarning': <class 'FutureWarning'>}, 'extend_path': <function extend_path at 0x7efdda38d048>}
I un-did everything I'd done with Jhbuild.
The program doesn't complain that the module is missing when I use python3.
But, I am not very used to python3 and would like to use python2.7 .
But, it complains me about module not being found which I try to run :
#!/usr/bin/python2
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Hello World")
self.button = Gtk.Button(label="Click Here")
self.button.connect("clicked", self.on_button_clicked)
self.add(self.button)
def on_button_clicked(self, widget):
print ("Hello World")
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
here's some output.
$ python -c "import gi; print(gi.__spec__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named gi
$ python -c "import gi; print(gi.__dict__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named gi
Last edited by bibek22 (2015-11-08 13:10:31)
Offline
But, I am not very used to python3 and would like to use python2.7 .
But, it complains me about module not being found which I try to run
If you want to use python2, you have to install python2-gobject.
Offline
That was exactly What I needed.
Offline
I don't know if my comment can help someone... But I had the same issue using Ubuntu 16.04. My issue was an update of the python package using 'pip':
My solution was to remove the package with pip and reinstall it with apt-get:
sudo -H pip uninstall gi
sudo apt-get install --reinstall python-gi
Regards.
Offline
1. Do not necrobump. The last post is one and a half years old. Pluss
2. I don't see the relevance. This is Arch Linux forums, supporting Arch Linux only.
Be aware of my Newbie Powers
Offline
Closing this old thread.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Pages: 1
Topic closed