You are not logged in.

#1 2015-10-08 07:36:37

jmartl109
Member
Registered: 2011-03-17
Posts: 25

[SOLVED] [python3] problems importing gobject module

There's an app that I've been trying to get to work in arch, and I'm stuck with what seems to be a more general problem dealing with python. The app is written in python3. The app has the following code:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

Now, if I just run these three lines in interactive python, I get:

$ python
Python 3.5.0 (default, Sep 20 2015, 11:28:25) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_version('Gtk', '3.0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'gi' has no attribute 'require_version'
>>> from gi.repository import Gtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'gi.repository'

Now, there are a billion threads about this on the internet, and they all boil down to not having python-gobject installed. But I do!

$ pacman -Q |grep gobject
gobject-introspection 1.44.0-1
gobject-introspection-runtime 1.44.0-1
pygobject-devel 3.16.2-2
pygobject2-devel 2.28.6-12
python-gobject 3.16.2-2
python-gobject2 2.28.6-12
python2-gobject 3.16.2-2
python2-gobject2 2.28.6-12

Moreover, I seem to have the right files corresponding to this gi.repository thing:

$ pacman -Ql python-gobject|grep repository
python-gobject /usr/lib/python3.5/site-packages/gi/repository/
python-gobject /usr/lib/python3.5/site-packages/gi/repository/__init__.py
python-gobject /usr/lib/python3.5/site-packages/gi/repository/__pycache__/
python-gobject /usr/lib/python3.5/site-packages/gi/repository/__pycache__/__init__.cpython-35.opt-1.pyc
python-gobject /usr/lib/python3.5/site-packages/gi/repository/__pycache__/__init__.cpython-35.pyc
$ tree /usr/lib/python3.5/site-packages/gi/repository/
/usr/lib/python3.5/site-packages/gi/repository/
├── __init__.py
└── __pycache__
    ├── __init__.cpython-35.opt-1.pyc
    └── __init__.cpython-35.pyc

1 directory, 3 files

For the record, python2 accepts the three lines above without complaint. But the app was clearly written for python3 (and lots of other bad things start happening if I s/python3/python2/) so I feel like I'm missing something...

Thanks!

Last edited by jmartl109 (2015-10-08 08:43:17)

Offline

#2 2015-10-08 08:03:55

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: [SOLVED] [python3] problems importing gobject module

The above commands work fine here with python3... can you 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__)"

About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

#3 2015-10-08 08:11:51

jmartl109
Member
Registered: 2011-03-17
Posts: 25

Re: [SOLVED] [python3] problems importing gobject module

$ which python
/usr/bin/python
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 7 Sep 20 07:48 /usr/bin/python -> python3*
$ pacman -Qikk python-gobject python
Name           : python-gobject
Version        : 3.16.2-2
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.16.2  python  cairo
Optional Deps  : None
Required By    : None
Optional For   : hplip  redshift
Conflicts With : None
Replaces       : None
Installed Size : 1060.00 KiB
Packager       : Felix Yan <felixonmars@archlinux.org>
Build Date     : Sat 19 Sep 2015 09:44:45 AM EDT
Install Date   : Thu 08 Oct 2015 02:22:27 AM EDT
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
                 sqlite [installed]
                 mpdecimal: for decimal
                 xz: for lzma [installed]
                 tk: for tkinter [installed]
Required By    : gdb  hplip  hugin  libreoffice-fresh  mono  pycp  python-dbus  python-gobject  python-gobject2  python-lxml  python-packaging  python-sip  python-xdg  ranger  units  youtube-dl
Optional For   : libnewt  lirc  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 07:48:48 AM EDT
Install Date   : Thu 01 Oct 2015 01:13:14 PM EDT
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 0x7fa1362f6240>, origin='/usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi/__init__.py', submodule_search_locations=['/usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi'])
$ python -c "import gi; print(gi.__dict__)"
{'__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f531021b240>, '__spec__': ModuleSpec(name='gi', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f531021b240>, origin='/usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi/__init__.py', submodule_search_locations=['/usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi']), 'GIST_API_URL': 'https://api.github.com/gists', '__cached__': '/usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi/__pycache__/__init__.cpython-35.pyc', '__package__': 'gi', '__file__': '/usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi/__init__.py', '__path__': ['/usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi'], '__doc__': None, '__name__': 'gi', 'save_file': <function save_file at 0x7f531020d2f0>, 'json': <module 'json' from '/usr/lib/python3.5/json/__init__.py'>, 'sys': <module 'sys' (built-in)>, '__builtins__': {'ChildProcessError': <class 'ChildProcessError'>, 'len': <built-in function len>, 'str': <class 'str'>, 'IsADirectoryError': <class 'IsADirectoryError'>, 'filter': <class 'filter'>, 'vars': <built-in function vars>, 'range': <class 'range'>, 'False': False, 'help': Type help() for interactive help, or help(object) for help about object., 'round': <built-in function round>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'oct': <built-in function oct>, 'PermissionError': <class 'PermissionError'>, 'repr': <built-in function repr>, 'BytesWarning': <class 'BytesWarning'>, 'ord': <built-in function ord>, 'zip': <class 'zip'>, 'UnicodeError': <class 'UnicodeError'>, 'exec': <built-in function exec>, 'divmod': <built-in function divmod>, 'ImportError': <class 'ImportError'>, '__build_class__': <built-in function __build_class__>, 'max': <built-in function max>, 'hasattr': <built-in function hasattr>, 'UnicodeWarning': <class 'UnicodeWarning'>, 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'TypeError': <class 'TypeError'>, 'SystemExit': <class 'SystemExit'>, 'float': <class 'float'>, 'classmethod': <class 'classmethod'>, 'chr': <built-in function chr>, 'KeyError': <class 'KeyError'>, 'UserWarning': <class 'UserWarning'>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'SystemError': <class 'SystemError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'super': <class 'super'>, 'EOFError': <class 'EOFError'>, 'None': None, 'map': <class 'map'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'input': <built-in function input>, 'isinstance': <built-in function isinstance>, 'RecursionError': <class 'RecursionError'>, 'sorted': <built-in function sorted>, 'ascii': <built-in function ascii>, 'SyntaxWarning': <class 'SyntaxWarning'>, 'object': <class 'object'>, 'NotADirectoryError': <class 'NotADirectoryError'>, 'IOError': <class 'OSError'>, 'IndexError': <class 'IndexError'>, 'ArithmeticError': <class 'ArithmeticError'>, 'StopIteration': <class 'StopIteration'>, 'iter': <built-in function iter>, 'EnvironmentError': <class 'OSError'>, 'license': Type license() to see the full license text, 'InterruptedError': <class 'InterruptedError'>, 'ValueError': <class 'ValueError'>, 'abs': <built-in function abs>, 'MemoryError': <class 'MemoryError'>, 'format': <built-in function format>, 'type': <class 'type'>, 'RuntimeError': <class 'RuntimeError'>, 'min': <built-in function min>, 'staticmethod': <class 'staticmethod'>, 'OverflowError': <class 'OverflowError'>, 'OSError': <class 'OSError'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, 'complex': <class 'complex'>, 'ResourceWarning': <class 'ResourceWarning'>, 'bytes': <class 'bytes'>, 'property': <class 'property'>, 'dict': <class 'dict'>, 'BaseException': <class 'BaseException'>, 'globals': <built-in function globals>, 'frozenset': <class 'frozenset'>, 'bin': <built-in function bin>, 'next': <built-in function next>, 'dir': <built-in function dir>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'TimeoutError': <class 'TimeoutError'>, 'callable': <built-in function callable>, 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", 'eval': <built-in function eval>, 'id': <built-in function id>, 'any': <built-in function any>, 'memoryview': <class 'memoryview'>, 'Exception': <class 'Exception'>, 'BlockingIOError': <class 'BlockingIOError'>, 'hash': <built-in function hash>, 'ReferenceError': <class 'ReferenceError'>, 'slice': <class 'slice'>, '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., 'reversed': <class 'reversed'>, '__name__': 'builtins', 'hex': <built-in function hex>, 'bool': <class 'bool'>, 'pow': <built-in function pow>, 'bytearray': <class 'bytearray'>, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'ImportWarning': <class 'ImportWarning'>, 'RuntimeWarning': <class 'RuntimeWarning'>, 'print': <built-in function print>, 'IndentationError': <class 'IndentationError'>, 'compile': <built-in function compile>, 'set': <class 'set'>, '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., 'GeneratorExit': <class 'GeneratorExit'>, 'NotImplementedError': <class 'NotImplementedError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'AssertionError': <class 'AssertionError'>, 'FloatingPointError': <class 'FloatingPointError'>, 'enumerate': <class 'enumerate'>, 'NotImplemented': NotImplemented, 'True': True, 'AttributeError': <class 'AttributeError'>, '__package__': '', 'Warning': <class 'Warning'>, 'issubclass': <built-in function issubclass>, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__debug__': True, 'getattr': <built-in function getattr>, '__import__': <built-in function __import__>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'NameError': <class 'NameError'>, 'FileNotFoundError': <class 'FileNotFoundError'>, 'tuple': <class 'tuple'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'ProcessLookupError': <class 'ProcessLookupError'>, '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>), 'Ellipsis': Ellipsis, 'SyntaxError': <class 'SyntaxError'>, 'all': <built-in function all>, 'BufferError': <class 'BufferError'>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'LookupError': <class 'LookupError'>, 'TabError': <class 'TabError'>, 'list': <class 'list'>, 'delattr': <built-in function delattr>, 'ConnectionError': <class 'ConnectionError'>, 'setattr': <built-in function setattr>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'StopAsyncIteration': <class 'StopAsyncIteration'>, 'FileExistsError': <class 'FileExistsError'>, 'locals': <built-in function locals>, 'FutureWarning': <class 'FutureWarning'>, 'open': <built-in function open>, 'sum': <built-in function sum>, 'int': <class 'int'>}, 'requests': <module 'requests' from '/usr/lib/python3.5/site-packages/requests-2.8.0-py3.5.egg/requests/__init__.py'>, 'GistError': <class 'gi.GistError'>}

Offline

#4 2015-10-08 08:19:38

Awebb
Member
Registered: 2010-05-06
Posts: 6,312

Re: [SOLVED] [python3] problems importing gobject module

I cannot reproduce the error. Steps:

1. Install python-gobject
2. $ python, it identifies as 3.5.0 with GCC 5.2.0
3. >>> import gi
4. >>> gi.require_version('Gtk', '3.0')
5. >>> from gi.repository import Gtk

No error messages whatsoever.

Offline

#5 2015-10-08 08:22:55

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: [SOLVED] [python3] problems importing gobject module

The path of the module is wrong, it should be /usr/lib/python3.5/site-packages/gi/__init__.py

$ python -c "import gi; print(gi.__spec__)"
ModuleSpec(name='gi', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f058a3e4978>, origin='/usr/lib/python3.5/site-packages/gi/__init__.py', submodule_search_locations=['/usr/lib/python3.5/site-packages/gi'])

What is the output of

$ pacman -Qo /usr/lib/python3.5/site-packages/gi-1.2-py3.5.egg/gi/__init__.py

?


About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

#6 2015-10-08 08:43:00

jmartl109
Member
Registered: 2011-03-17
Posts: 25

Re: [SOLVED] [python3] problems importing gobject module

Ah, you're right -- that wasn't owned by any package. So I removed python-gobject, and the directory you pointed out, reinstalled python-gobject and now it works.

Thanks!

Offline

Board footer

Powered by FluxBB