Use GdkPixbuf in Python app within Flatpak

I am trying to use GdkPixbuf as follows in my Python application:

file = Gio.File("/path/to/img.jpg")
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file.get_path(), 200, 200, preserve_aspect_ratio=True)

However, when I run this with Flatpak from Gnome Builder, I get the following error:

future: <GLibTask finished name='None' coro=<myfunc() done, defined at /app/share/myapp/myapp/myfile.py:123> exception=GLib.Error('Loader process exited early with status '1'Command:
 env -i XDG_RUNTIME_DIR="/run/user/1000" "flatpak-spawn" "--sandbox" "--watch-bus" "--directory=/" "--forward-fd=47" "prlimit" "--as=16464950067" "/usr/libexec/glycin-loaders/2+/glycin-image-rs" "--dbus-fd" "47"', 'gdk-pixbuf-error-quark', 0)>
Traceback (most recent call last):
  File "/app/share/myapp/myapp/myfile.py", line 132, in _set_image_file
    pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file.get_path(), 200, 200, preserve_aspect_ratio=True)
gi.repository.GLib.GError: gdk-pixbuf-error-quark: Loader process exited early with status '1'Command:
 env -i XDG_RUNTIME_DIR="/run/user/1000" "flatpak-spawn" "--sandbox" "--watch-bus" "--directory=/" "--forward-fd=47" "prlimit" "--as=16464950067" "/usr/libexec/glycin-loaders/2+/glycin-image-rs" "--dbus-fd" "47" (0)

When I set a breakpoint with pdb and run above command, I get:

(Pdb) os.system("/usr/libexec/glycin-loaders/2+/glycin-image-rs --dbus-fd 47 gdk-pixbuf-error-quark 0")

thread 'main' (15) panicked at /buildstream/gnome/sdk/glycin.bst/.vendored-crates/glycin-utils-4.0.4/src/instruction_handler.rs:100:14:
Failed to create private DBus connection: InputOutput(Os { code: 9, kind: Uncategorized, message: "Bad file descriptor" })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
25856

Does anyone has succeeded in making this run?

Hi,

Sounds like glycin couldn’t detect the correct sandboxing mechanism.

Have a look here: Gly.SandboxSelector

→ If your flatpak is not installed (i.e. you start it with flatpak-builder --run) then make sure the app-ID ends with .Devel.

1 Like

I noticed something strange. When I generate and export a .flatpak file with Gnome Builder via the “export” option in the dropdown menu at the top, and install it afterwards using flatpak install, then creating the pixbuf works… When I uninstall it, it crashes again.

Thank you. This must be the solution. When I append .Devel to my application ID, it does work and only throws the following warning:

WARNING: Glycin running without sandbox.