1

I managed to get an old Python 2 app running on Xenial, but the menus aren't working and i've since borked that particular installation (can be recovered i guess). I was told this "used to work in a windows vm" so am having a go at it.

I already had msys, added some gtk dependencies and spent the better part of two days tracking down and installing old packages to satisfy more dependencies, using pip, wheels, pypi and, more frequently than not, scavenging old versions that still supported Python 2 in git repos and then setup.py install them, sometimes with the help of Microsoft Visual C++ 9.0.


Now i hit the same error i once had in Xenial: GLib.Error: ... Required gtk+ version 3.20, current version is 3.18 (7), only then i think solved it by compiling pygobject but i don't recall it.


I've installed the GTK and Gdk components of PyGObject for windows onto my /c/Python27/ msys installation, and i have these msys packages installed (relevant to this):

$ pacman -Ss glade
mingw32/mingw-w64-i686-glade 3.38.2-1
    User interface builder for GTK+ and GNOME (mingw-w64)
mingw32/mingw-w64-i686-glade-gtk2 3.8.6-4
    User interface builder for GTK+ and GNOME (mingw-w64)
mingw32/mingw-w64-i686-libglade 2.6.4-6
    Allows you to load glade interface files in a program at runtime (mingw-w64)
mingw64/mingw-w64-x86_64-glade 3.38.2-1 [installed]
    User interface builder for GTK+ and GNOME (mingw-w64)
mingw64/mingw-w64-x86_64-glade-gtk2 3.8.6-4 [installed]
    User interface builder for GTK+ and GNOME (mingw-w64)
mingw64/mingw-w64-x86_64-libglade 2.6.4-6 [installed]
    Allows you to load glade interface files in a program at runtime (mingw-w64)
ucrt64/mingw-w64-ucrt-x86_64-glade 3.38.2-1
    User interface builder for GTK+ and GNOME (mingw-w64)
ucrt64/mingw-w64-ucrt-x86_64-glade-gtk2 3.8.6-4
    User interface builder for GTK+ and GNOME (mingw-w64)
ucrt64/mingw-w64-ucrt-x86_64-libglade 2.6.4-6
    Allows you to load glade interface files in a program at runtime (mingw-w64)
clang64/mingw-w64-clang-x86_64-glade 3.38.2-1
    User interface builder for GTK+ and GNOME (mingw-w64)
clang64/mingw-w64-clang-x86_64-glade-gtk2 3.8.6-4
    User interface builder for GTK+ and GNOME (mingw-w64)
clang64/mingw-w64-clang-x86_64-libglade 2.6.4-6
    Allows you to load glade interface files in a program at runtime (mingw-w64)
$ pacman -Ss gtk | grep ^mingw64
...
mingw64/mingw-w64-x86_64-glade 3.38.2-1 [installed]
mingw64/mingw-w64-x86_64-glade-gtk2 3.8.6-4 [installed]
mingw64/mingw-w64-x86_64-glib2 2.70.4-1 [installed]
...
mingw64/mingw-w64-x86_64-gtk-engines 2.21.0-4
mingw64/mingw-w64-x86_64-gtk-update-icon-cache 3.24.31+76+g3dc44becf0-1 [installed]
mingw64/mingw-w64-x86_64-gtk2 2.24.33-4 [installed]
mingw64/mingw-w64-x86_64-gtk3 3.24.31+76+g3dc44becf0-1 [installed]
mingw64/mingw-w64-x86_64-gtk4 4.6.1-1
mingw64/mingw-w64-x86_64-gtkada 3.8.2-2
...
mingw64/mingw-w64-x86_64-python-gobject 3.40.1-2 [installed]
mingw64/mingw-w64-x86_64-python2-pygtk 2.24.0-8 [installed]
...
$ pacman -Ss python | grep ^mingw64| grep installed
mingw64/mingw-w64-x86_64-python 3.9.10-2 [installed]
mingw64/mingw-w64-x86_64-python-cairo 1.20.1-2 [installed]
mingw64/mingw-w64-x86_64-python-gobject 3.40.1-2 [installed]
mingw64/mingw-w64-x86_64-python-pillow 9.0.1-1 [installed]
mingw64/mingw-w64-x86_64-python2 2.7.18-4 [installed]
mingw64/mingw-w64-x86_64-python2-cairo 1.18.2-3 [installed]
mingw64/mingw-w64-x86_64-python2-gobject2 2.28.7-3 [installed]
mingw64/mingw-w64-x86_64-python2-pygtk 2.24.0-8 [installed]

My C:\Python27\Lib\site-packages\easy-install.pth has nothing GTK-related:

import sys; sys.__plen = len(sys.path)
./sqlalchemy-1.4.31-py2.7-win-amd64.egg
./sqlalchemy-1.4.31dev-py2.7-win-amd64.egg
./configparser-0.0.0-py2.7.egg
./contextlib2-0.6.0-py2.7.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)

I've appended /mingw64/lib/python3.9/site-packages/ to my app's sys.path:

sys.path.append('/mingw64/lib/python2.7/site-packages/gtk-2.0')
sys.path.append('/mingw64/lib/python2.7/site-packages')
sys.path.append('/c/Python27/lib/site-packages')

This is because i'm using /c/Python27/python.exe and its lib/site-packages is where all the fun is at, but i get the same result with /mingw64/bin/python2.7.exe.

Python's not my forte nor will i upgrade this app to Python 3. How do i go about upgrading gtk?


Edit1

According to GTK's website i should use mysys, which i have, and the version should suffice:

$ pacman -Qi mingw-w64-x86_64-gtk3
Name            : mingw-w64-x86_64-gtk3
Version         : 3.24.31+76+g3dc44becf0-1

(I even ended up compiling the latest mysys GTK3 which caused only a minor version bump.)

My script loads glade data:

builder = Gtk.Builder()
builder.add_from_file("xmlfile")

The file has:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
  <requires lib="gtk+" version="3.20"/>

and thus it fails, because it's fetching GTK from PyGObject for windows instead of the msys env.

C:\Python27\Lib\site-packages\gnome\libgtk-3-0.dll is 3.18.9
C:\msys64\mingw64\bin\libgtk-3-0.dll is 3.24.31

PyGobject on msys seems to be fairily up-to-date (no GTK changes from my installed 3.40.1 to 3.42.0), but Python2 support has apparently been dropped in 3.38.0.

I can't just replace the .dll in gnome\ and can't seem to get python to use the one in bin\ atm.


Recompiling mingw-w64-pygobject2 didn't quite help: the last version to support Python 2 is 3.36.0 but using msys to build anything other than that version, ahead or before, yileds patching errors.

vesperto
  • 804
  • 1
  • 6
  • 26

0 Answers0