Error running script with python 3.10

I have a script that I regularly run to backup my gramps databases. At the start of the script I import ‘exportpkg’. Since I upgraded to Ubuntu 22.04 I am now getting the stack trace below. Given that the stack is started from an import, this seems like a bug in gramps. Have others seen this?

Ubuntu Linux 22.04
Gramps installed via deb version 5.1.5.
python 3.10

Traceback (most recent call last):
  File "/home/jpschewe/bin/gramps-backup", line 31, in <module>
    import gramps.plugins.export.exportpkg as exportpkg
  File "/usr/lib/python3/dist-packages/gramps/plugins/export/exportpkg.py", line 60, in <module>
    from gramps.gui.plug.export import WriterOptionBox
  File "/usr/lib/python3/dist-packages/gramps/gui/plug/__init__.py", line 31, in <module>
    from ._guioptions import make_gui_option, add_gui_options
  File "/usr/lib/python3/dist-packages/gramps/gui/plug/_guioptions.py", line 54, in <module>
    from .. import widgets
  File "/usr/lib/python3/dist-packages/gramps/gui/widgets/__init__.py", line 26, in <module>
    from .buttons import *
  File "/usr/lib/python3/dist-packages/gramps/gui/widgets/buttons.py", line 47, in <module>
    class IconButton(Gtk.Button):
  File "/usr/lib/python3/dist-packages/gramps/gui/widgets/buttons.py", line 49, in IconButton
    def __init__(self, func, handle, icon='gtk-edit', size=Gtk.IconSize.MENU):
AttributeError: type object 'IconSize' has no attribute 'MENU'

I suspect that the problem is that Gtk was also upgraded to a higher version. The Gtk.IconSize.MENU seems to have been deprecated for quite a while; the Gtk folks may have dropped support for that functionality.

Can you report on the Gtk version? This can be shown by starting Gramps with the -v option from the command line.

We will have to fix up Gramps to deal with this if the version of Gtk becomes common…

can you attache an example of your script that causes the problem?

>gramps -v
Gramps Settings:
----------------
 python    : 3.10.4
 gramps    : 5.1.5
 gtk++     : 3.24.33
 pygobject : 3.42.1
 pango     : 1.50.6
 cairo     : 1.16.0
 pycairo   : 1.20.1
 osmgpsmap : 1.0
 GExiv2    : 0.10
 ICU       : not found
 PyICU     : not found
 o.s.      : linux
 kernel    : 5.18.10-76051810-generic

This script will cause the error

#!/usr/bin/env python3

import warnings
with warnings.catch_warnings():
    import gramps.plugins.export.exportpkg as exportpkg
>python3 --version
Python 3.10.4

Note that I also get a warning about how gtk is imported.

/usr/lib/python3/dist-packages/gramps/plugins/export/exportpkg.py:53: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '4.0') before import to ensure that the right version gets loaded.

my environment is different (probably simpler), but so far haven’t been able to reproduce your stack trace using the script you sent.

gramps -v

python : 3.10.6 (yours 3.10.4)
gramps : 5.1.5
gtk++ : 3.24.34 (yours 3.24.33)
pygobject : 3.42.2 (yours 3.42.1)
pango : 1.50.9
cairo : 1.16.0
pycairo : 1.20.1
osmgpsmap : 1.0
GExiv2 : 0.10
ICU : not found
PyICU : not found
o.s. : linux
kernel : 5.18.0-4-amd64

so I have slight newer versions of some things, Interestingly, your warning message has:
Use gi.require_version(‘Gtk’, ‘4.0’)

mine, with the slightly newer librarys suggests an older version:
Use gi.require_version(‘Gtk’, '3.0’)

“/usr/lib/python3/dist-packages/gramps/plugins/export/exportpkg.py:53: 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. from gi.repository import Gtk”

I’m just trying to find a simple case that causes your issue.
what am i missing?

I’m guessing something else in my environment is bringing in gtk 4.0 and gramps appears to only support gtk 3.0. Based on your warning I modified my script and this one runs without error

#!/usr/bin/env python3

import warnings
with warnings.catch_warnings():
    import gi
    gi.require_version('Gtk', '3.0')
    import gramps.plugins.export.exportpkg as exportpkg
    

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.