Repository: pyinstaller/pyinstaller

Issue:
Gtk libpixbufloader-png.dll load path is not relative - exe will crash if run on another machine
<!--
Welcome to the PyInstaller issue tracker! Before creating an issue, please heed the following:

1. This tracker should only be used to report bugs and request features / enhancements to PyInstaller
    - For questions and general support, use the discussions forum.
2. Use the search function before creating a new issue. Duplicates will be closed and directed to
   the original discussion.
3. When making a bug report, make sure you provide all required information. The easier it is for
   maintainers to reproduce, the faster it'll be fixed.
-->

<!-- +++ ONLY TEXT +++ DO NOT POST IMAGES +++ -->

## Description of the issue
I compiled my app which uses GdkPixbuf. When compiled, it looks for the dll using the absolute path of the machine that compiled it. It runs on my dev machine but when I move the same exe to another machine, it crashes because it is not looking for the dll in the relative path.

eg. (Note that C:/tools/msys64/mingw64/bin/ is a path that is local to the machine, and it should be looking for it from the lib folder)
`Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll`

I can no longer build working exe.
```
Gtk:ERROR:../gtk/gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found. (gdk-pixbuf-error-quark, 5)
Bail out! Gtk:ERROR:../gtk/gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found. (gdk-pixbuf-error-quark, 5)
```

Note that that in order to reproduce this issue, I have to use this workaround:
https://github.com/pyinstaller/pyinstaller/issues/7833

I also tried the latest development version but that is broken because all of the dlls are packaged in the _internal folder.

### Context information (for bug reports)

* Output of `pyinstaller --version`: ```5.13.0```
* Version of Python: 3.11.4
* Platform: Windows 11
* How you installed Python: msys2
* Did you also try this on another platform? Does it work there? I have not, my program is supposed to run in Windows


* try the latest development version, using the following command:

```shell
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
```

* follow *all* the instructions in our "If Things Go Wrong" Guide
  (https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong) and

### Make sure [everything is packaged correctly](https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs#make-sure-everything-is-packaged-correctly)

  * [X] start with clean installation
  * [X] use the latest development version
  * [X] Run your frozen program **from a command window (shell)** — instead of double-clicking on it
  * [ ] Package your program in **--onedir mode**
  * [ ] Package **without UPX**, say: use the option `--noupx` or set `upx=False` in your .spec-file
  * [ ] Repackage you application in **verbose/debug mode**. For this, pass the option `--debug` to `pyi-makespec` or `pyinstaller` or use `EXE(..., debug=1, ...)` in your .spec file.


### A minimal example program which shows the error
Example taken from here: https://askubuntu.com/questions/165276/load-and-show-an-image-from-the-web-in-python-with-gtk-3
```
import os
import urllib2
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf


def quit_event(widget, event):
    os.remove(imgname)
    Gtk.main_quit()

imgname = '1338.jpg'
url = 'http://lolcat.com/images/lolcats/'+imgname
response = urllib2.urlopen(url)
with open(imgname, 'wb') as img:
    img.write(response.read())

image = Gtk.Image()
pb = Pixbuf.new_from_file(imgname)
image.set_from_pixbuf(pb)

window = Gtk.Window()
window.connect('delete-event', quit_event)
window.add(image)
window.show_all()
Gtk.main()
```

### Stacktrace / full error message


```
(displayin.exe:9600): Gtk-WARNING **: 12:31:37.310: Could not load image '../images/DisplayInIcon.ico': Failed to open file ?C:\Users\coolc\Documents\DisplayIn\displayin\resource/ui\../images/DisplayInIcon.ico?: No such file or directory

(displayin.exe:9600): Gtk-WARNING **: 12:31:37.604: Could not load a pixbuf from /org/gtk/libgtk/icons/16x16/status/image-missing.png.
This may indicate that pixbuf loaders or the mime database could not be found.

(displayin.exe:9600): Gtk-WARNING **: 12:31:37.673: Error loading theme icon 'image-missing' for stock: Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found.

(displayin.exe:9600): Gtk-WARNING **: 12:31:37.673: Error loading theme icon 'image-missing' for stock: Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found.

(displayin.exe:9600): Gdk-CRITICAL **: 12:31:37.673: gdk_cairo_surface_create_from_pixbuf: assertion 'GDK_IS_PIXBUF (pixbuf)' failed
ui/mainwindow.py:51: Warning: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

(displayin.exe:9600): Gtk-WARNING **: 12:31:37.673: Error loading theme icon 'image-missing' for stock: Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found.

(displayin.exe:9600): Gtk-WARNING **: 12:31:37.689: Error loading theme icon 'image-missing' for stock: Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found.

(displayin.exe:9600): Gdk-CRITICAL **: 12:31:37.689: gdk_cairo_surface_create_from_pixbuf: assertion 'GDK_IS_PIXBUF (pixbuf)' failed
Initializing Video...
[ WARN:0@2.095] global cap_gstreamer.cpp:1728 open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Display 0
Current Selected Device: 0
[ WARN:0@2.368] global cap_gstreamer.cpp:2784 handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module mfvideosrc1 reported: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
[ WARN:0@2.368] global cap_gstreamer.cpp:1679 open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@2.369] global cap_gstreamer.cpp:1164 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0@2.809] global cap_gstreamer.cpp:1728 open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
[ WARN:0@3.133] global cap_gstreamer.cpp:2099 setProperty OpenCV | GStreamer warning: GStreamer: unhandled property
[ WARN:0@3.866] global cap_gstreamer.cpp:2099 setProperty OpenCV | GStreamer warning: GStreamer: unhandled property
Video Started!

(displayin.exe:9600): Gtk-CRITICAL **: 12:31:41.251: gtk_entry_set_text: assertion 'text != NULL' failed
Video Initialized!
Initializing Audio...
Audio Started!

(displayin.exe:9600): Gtk-CRITICAL **: 12:31:41.273: gtk_entry_set_text: assertion 'text != NULL' failed
Audio Started!
Audio Started!
Audio Started!
Audio Started!
Audio Started!
Audio Started!

(displayin.exe:9600): Gtk-CRITICAL **: 12:31:41.361: gtk_entry_set_text: assertion 'text != NULL' failed
Audio Started!
Audio Started!
Audio Initialized!
**
Gtk:ERROR:../gtk/gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found. (gdk-pixbuf-error-quark, 5)
Bail out! Gtk:ERROR:../gtk/gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unable to load image-loading module: C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-png.dll': The specified module could not be found. (gdk-pixbuf-error-quark, 5)
```

Please also see <https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs>
for more about what would use to solve the issue.



Discussion:
I think I might have a potential fix. Let me test this and see if this fixes the issue:

hook-gi.repository.GdkPixbuf.py
```
def _collect_loaders(libdir):
    # Assume loader plugins have .so library suffix on all non-Windows platforms
    lib_ext = "*.dll" if compat.is_win else "*.so"

    # Find all loaders
    loader_libs = []
    pattern = os.path.join(libdir, LOADERS_PATH, lib_ext)
    for f in glob.glob(pattern):
        loader_libs.append(f)

    # Sometimes the loaders are stored in a different directory from the library (msys2)
    if not loader_libs:
        pattern = os.path.abspath(os.path.join(libdir, '..', 'lib', LOADERS_PATH, lib_ext))
        for f in glob.glob(pattern):
            loader_libs.append(f)

    return loader_libs
```

This at least fixes the error messges:
```
17182 INFO: Loading module hook 'hook-gi.repository.GdkPixbuf.py' from 'C:/tools/msys64/mingw64/lib/python3.11/site-packages/PyInstaller/hooks'...
g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/io-wmf.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/io-wmf.dll': The specified procedure could not be found.
g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-heif.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-heif.dll': The specified procedure could not be found.
g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll': The specified procedure could not be found.
g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-tiff.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-tiff.dll': The specified procedure could not be found.
18066 INFO: Processing pre-safe import module hook gi.repository.GModule from 'C:/tools/msys64/mingw64/lib/python3.11/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.GModule.py'.
```
> I think I might have a potential fix. Let me test this and see if this fixes the issue:
> 
> hook-gi.repository.GdkPixbuf.py
> 
> ```
> def _collect_loaders(libdir):
>     # Assume loader plugins have .so library suffix on all non-Windows platforms
>     lib_ext = "*.dll" if compat.is_win else "*.so"
> 
>     # Find all loaders
>     loader_libs = []
>     pattern = os.path.join(libdir, LOADERS_PATH, lib_ext)
>     for f in glob.glob(pattern):
>         loader_libs.append(f)
> 
>     # Sometimes the loaders are stored in a different directory from the library (msys2)
>     if not loader_libs:
>         pattern = os.path.abspath(os.path.join(libdir, '..', 'lib', LOADERS_PATH, lib_ext))
>         for f in glob.glob(pattern):
>             loader_libs.append(f)
> 
>     return loader_libs
> ```
> 
> This at least fixes the error messges:
> 
> ```
> 17182 INFO: Loading module hook 'hook-gi.repository.GdkPixbuf.py' from 'C:/tools/msys64/mingw64/lib/python3.11/site-packages/PyInstaller/hooks'...
> g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/io-wmf.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/io-wmf.dll': The specified procedure could not be found.
> g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-heif.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-heif.dll': The specified procedure could not be found.
> g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll': The specified procedure could not be found.
> g_module_open() failed for C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-tiff.dll: 'C:/tools/msys64/mingw64/bin/../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-tiff.dll': The specified procedure could not be found.
> 18066 INFO: Processing pre-safe import module hook gi.repository.GModule from 'C:/tools/msys64/mingw64/lib/python3.11/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-gi.repository.GModule.py'.
> ```

Spoke too soon, did not fix the issue:
```
12558 INFO: Loading module hook 'hook-gi.repository.GdkPixbuf.py' from 'C:/tools/msys64/mingw64/lib/python3.11/site-packages/PyInstaller/hooks'...
g_module_open() failed for C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/io-wmf.dll: 'C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/io-wmf.dll': The specified procedure could not be found.
g_module_open() failed for C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-heif.dll: 'C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-heif.dll': The specified procedure could not be found.
g_module_open() failed for C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll: 'C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll': The specified procedure could not be found.
g_module_open() failed for C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-tiff.dll: 'C:/tools/msys64/mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-tiff.dll': The specified procedure could not be found.
```
Also running this command multiple times:
`pyinstaller --noconsole --add-data="resource/ui/maingui.glade;resource/ui" --splash "resource/images/DisplayInSplash.png" --icon="resource/images/DisplayInIcon.ico" --onedir displayin.py`

Will sometimes produce an exe that launches. But other times produce an exe that will crash with the following message. The issue seems to be with the gdk-pixbuf libraries.
```
Traceback (most recent call last):
  File "displayin.py", line 2, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 385, in exec_module
  File "ui/mainwindow.py", line 2, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 385, in exec_module
  File "config/videostreamconfig.py", line 1, in <module>
  File "C:/Users/cley/git/DisplayIn/src/displayin/dist/displayin/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "C:/Users/cley/git/DisplayIn/src/displayin/dist/displayin/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "importlib/__init__.py", line 126, in import_module
ImportError: DLL load failed while importing cv2: The specified procedure could not be found.
```

EDIT:
disregard this comment, I was able to avoid this new error this by referencing the dlls with --add-binary instead of copying them manually in a bash script. The original issue still isn't fixed.
```
pyinstaller --add-data="resource/ui/maingui.glade;resource/ui" --splash "resource/images/DisplayInSplash.png" --icon="resource/images/DisplayInIcon.ico" --onedir displayin.py \
--add-binary "C:\tools\msys64\mingw64\lib\gdk-pixbuf-2.0\2.10.0\loaders\libpixbufloader-png.dll;lib\gdk-pixbuf\loaders" \
--add-binary "C:\tools\msys64\mingw64\bin\libGLESv2.dll;lib\opencv\bin" \
--add-binary "C:\tools\msys64\mingw64\bin\libEGL.dll;lib\opencv\bin" \
--add-binary "C:\tools\msys64\mingw64\bin\libIex-3_1.dll;lib\opencv\bin" \
--add-binary "C:\tools\msys64\mingw64\bin\libIlmThread-3_1.dll;lib\opencv\bin" \
--add-binary "C:\tools\msys64\mingw64\bin\libImath-3_1.dll;lib\opencv\bin" \
--add-binary "C:\tools\msys64\mingw64\bin\libOpenEXR-3_1.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstapp-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstaudio-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstbase-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstpbutils-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstreamer-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstriff-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gsttag-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstvideo-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\gstd3d11-1.0-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\bin\orc-0.4-0.dll;lib\opencv\bin" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstapp.dll;lib\opencv\lib\gstreamer-1.0" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstmediafoundation.dll;lib\opencv\lib\gstreamer-1.0" \
--add-binary "F:\gstreamer\1.0\msvc_x86_64\lib\gstreamer-1.0\gstvideoconvertscale.dll;lib\opencv\lib\gstreamer-1.0" \
--add-binary "C:\Windows\System32\vcruntime140_1.dll;lib\opencv\bin"
```
I cannot reproduce this; the following test program (a slightly simplified version of yours), built in msys2/mingw64 on one Win10 machine works just fine on a different Win10 machine:

<details><summary>program.py</summary><p>

```python
import os
import gi
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf

def quit_event(widget, event):
    Gtk.main_quit()

imgname = os.path.join(os.path.dirname(__file__), 'image.png')  # --add-data "image.png;."

image = Gtk.Image()
pb = Pixbuf.new_from_file(imgname)
image.set_from_pixbuf(pb)

window = Gtk.Window()
window.connect('delete-event', quit_event)
window.add(image)
window.show_all()
Gtk.main()
``` 

<p></details>


And if I intentionally remove the `libpixbufloader-png.dll` from the onedir build, the error indicates that it is being sought in correct place:
```
Traceback (most recent call last):
  File "program.py", line 15, in <module>
gi.repository.GLib.GError: gdk-pixbuf-error-quark: Unable to load image-loading module: C:\Users\Rok\Desktop\dist-513\program\lib\gdk-pixbuf\loaders\libpixbufloader-png.dll: 'C:\Users\Rok\Desktop\dist-513\program\lib\gdk-pixbuf\loaders\libpixbufloader-png.dll': The specified module could not be found. (5)
[6932] Failed to execute script 'program' due to unhandled exception!
```

Can you try building and testing with minimal example (so we can rule out influence of external gstreamer libs, and the noise coming from gstreamer and opencv)?

If minimal example does not work for you either, can you check what the entries in `dist/<name>/lib/gdk-pixbuf/loaders.cache` look like? Are they relative paths, like
```

"lib\\gdk-pixbuf\\loaders\\libpixbufloader-png.dll"
"png" 5 "gdk-pixbuf" "PNG" "LGPL"
"image/png" ""
"png" ""
"\211PNG\r\n\032\n" "" 100
```
or do they happen to be absolute paths? What do the entries in the original `loaders.cache` (` /mingw64/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache`) look like?

Resolving patch:
diff --git a/PyInstaller/hooks/hook-gi.repository.GdkPixbuf.py b/PyInstaller/hooks/hook-gi.repository.GdkPixbuf.py
--- a/PyInstaller/hooks/hook-gi.repository.GdkPixbuf.py
+++ b/PyInstaller/hooks/hook-gi.repository.GdkPixbuf.py
@@ -52,7 +52,7 @@ def _collect_loaders(libdir):
 
     # Sometimes the loaders are stored in a different directory from the library (msys2)
     if not loader_libs:
-        pattern = os.path.join(libdir, '..', 'lib', LOADERS_PATH, lib_ext)
+        pattern = os.path.abspath(os.path.join(libdir, '..', 'lib', LOADERS_PATH, lib_ext))
         for f in glob.glob(pattern):
             loader_libs.append(f)
 
@@ -89,6 +89,9 @@ def _generate_loader_cache(gdk_pixbuf_query_loaders, libdir, loader_libs):
     win_prefix = '"' + '\\\\'.join(['lib', 'gdk-pixbuf-2.0', '2.10.0'])
     win_plen = len(win_prefix)
 
+    msys2_prefix = '"' + os.path.abspath(os.path.join(libdir, '..', 'lib', 'gdk-pixbuf-2.0', '2.10.0'))
+    msys2_plen = len(msys2_prefix)
+
     # For each line in the updated loader cache...
     for line in cachedata.splitlines():
         if line.startswith('#'):
@@ -97,6 +100,8 @@ def _generate_loader_cache(gdk_pixbuf_query_loaders, libdir, loader_libs):
             line = '"@executable_path/' + LOADER_CACHE_DEST_PATH + line[plen:]
         elif line.startswith(win_prefix):
             line = '"' + LOADER_CACHE_DEST_PATH.replace('/', '\\\\') + line[win_plen:]
+        elif line.startswith(msys2_prefix):
+            line = ('"' + LOADER_CACHE_DEST_PATH + line[msys2_plen:]).replace('/', '\\\\')
         output_lines.append(line)
 
     return '\n'.join(output_lines)


Test patch: