GNOME Bugzilla – Bug 682051
Import errors building with Python 3.3
Last modified: 2012-08-21 06:02:58 UTC
While trying to build pygobject with Python 3.3 a few erronous import errors popped up do to changes in 3.3. It looks like using invalid items in fromlist for __import__ and PyImport_ImportModuleEx now raise an ImportError. I've logged: http://bugs.python.org/issue15715 just for tracking the behavioural change, but these things should be cleaned up on the pygobject side anyway. $ python3.3 -c "import gi" Traceback (most recent call last):
+ Trace 230686
from ._gi import _API, Repository
AND $ make check Traceback (most recent call last): File "./runtests.py", line 44, in <module> suite = loader.loadTestsFromNames(names) File "/usr/local/lib/python3.3/unittest/loader.py", line 137, in loadTestsFromNames suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/local/lib/python3.3/unittest/loader.py", line 137, in <listcomp> suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/local/lib/python3.3/unittest/loader.py", line 96, in loadTestsFromName module = __import__('.'.join(parts_copy)) File "/home/simon/src/gnome3/pygobject/tests/test_gobject.py", line 6, in <module> from gi.repository import GObject File "/home/simon/src/gnome3/pygobject/gi/importer.py", line 76, in load_module dynamic_module._load() File "/home/simon/src/gnome3/pygobject/gi/module.py", line 244, in _load overrides_modules = __import__('gi.overrides', fromlist=[self._namespace]) ImportError: No module named 'gi.overrides.GObject'
Created attachment 221523 [details] [review] Fixed erronous import statements for Python 3.3 Updated pygobject/gi/pygobject-external to use GType (which is what GTypeWrapper is exposed as) instead of GTypeWrapper when attempting import. Added try/except on ImportError around attempted imports of a typelibs override file which don't always exist (GObject...)
With python3.3 I also encounter another problem which happens even earlier: Traceback (most recent call last):
+ Trace 230703
suite = loader.loadTestsFromNames(names)
suites = [self.loadTestsFromName(name, module) for name in names]
module = __import__('.'.join(parts_copy))
from gi.repository import GObject
Don't you get this as well?
My previous comment looks like http://bugs.python.org/issue15610. Your patch looks good, though, and does work fine with Python 2.7 and 3.2, so I pushed it. Thanks!
Hi Martin, I was testing with the beta 2 which looks like http://bugs.python.org/issue15610 was fixed so I didn't run into it. It seems the python devs are recommending using importlib instead of __import__ so I've logged: https://bugzilla.gnome.org/show_bug.cgi?id=682320 The next thing I ran into with python 3.3 is logged here: https://bugzilla.gnome.org/show_bug.cgi?id=682323
Ah, right. I used 3.3beta1 for testing.