# Error running script with python 3.10

**URL:** <https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699>\
**Category:** Help\
**Created:** [August 16, 2022, 12:37pm UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699 "2022-08-16T12:37:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpschewe](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/jpschewe/32/786_2.png) [@jpschewe](https://gramps.discourse.group/u/jpschewe)\
**Post date:** [August 16, 2022, 12:37pm UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/1 "2022-08-16T12:37:32Z")

</div>

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

```auto
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'

```

---

<div class="post-metadata">

**Author:** ![prculley](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/prculley/32/41_2.png) [@prculley](https://gramps.discourse.group/u/prculley)\
**Post date:** [August 16, 2022, 4:24pm UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/2 "2022-08-16T16:24:01Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![lordemannd](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/lordemannd/32/583_2.png) [@lordemannd](https://gramps.discourse.group/u/lordemannd)\
**Post date:** [August 16, 2022, 5:40pm UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/3 "2022-08-16T17:40:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpschewe](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/jpschewe/32/786_2.png) [@jpschewe](https://gramps.discourse.group/u/jpschewe)\
**Post date:** [August 17, 2022, 1:14am UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/4 "2022-08-17T01:14:06Z")

</div>

```auto
>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

```

---

<div class="post-metadata">

**Author:** ![jpschewe](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/jpschewe/32/786_2.png) [@jpschewe](https://gramps.discourse.group/u/jpschewe)\
**Post date:** [August 17, 2022, 1:15am UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/5 "2022-08-17T01:15:44Z")

</div>

This script will cause the error

```auto
#!/usr/bin/env python3

import warnings
with warnings.catch_warnings():
    import gramps.plugins.export.exportpkg as exportpkg

```

```auto
>python3 --version
Python 3.10.4

```

---

<div class="post-metadata">

**Author:** ![jpschewe](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/jpschewe/32/786_2.png) [@jpschewe](https://gramps.discourse.group/u/jpschewe)\
**Post date:** [August 17, 2022, 1:16am UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/6 "2022-08-17T01:16:13Z")

</div>

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

```auto
/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.

```

---

<div class="post-metadata">

**Author:** ![lordemannd](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/lordemannd/32/583_2.png) [@lordemannd](https://gramps.discourse.group/u/lordemannd)\
**Post date:** [August 17, 2022, 6:17pm UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/7 "2022-08-17T18:17:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jpschewe](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/jpschewe/32/786_2.png) [@jpschewe](https://gramps.discourse.group/u/jpschewe)\
**Post date:** [August 18, 2022, 1:35am UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/8 "2022-08-18T01:35:42Z")

</div>

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

```auto
#!/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
    

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/2ac1e712b7adf612e31ca08a55419f4cf37c0158.png) [@system](https://gramps.discourse.group/u/system)\
**Post date:** [September 17, 2022, 1:36am UTC](https://gramps.discourse.group/t/error-running-script-with-python-3-10/2699/9 "2022-09-17T01:36:39Z")

</div>

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