QDesktopServices fails to open PDF with Evince

65 views
Skip to first unread message

Efrem Braun

unread,
Mar 12, 2021, 4:23:10 AM3/12/21
to PyInstaller
I'm using PyInstaller to bundle a PySide2 application. In my application, I use QDesktopServices.openUrl (https://doc.qt.io/qt-5/qdesktopservices.html#openUrl) to open a PDF version of the user manual when the user clicks on the Help menu.

This works fine when I run the PySide2 application from terminal, whether it's on my Mac, Windows, or Ubuntu machines; it opens the manual in Preview, Microsoft Edge, and Evince, respectively. However, when I use PyInstaller to bundle the application via `pyinstaller MainWindow.py`, I get the following error on Ubuntu when I try to open the PDF:
`evince: error while loading shared libraries: libgdk-3.so.0: failed to map segment from shared object`

If I remove libgdk-3.so from the application bundle, I get the error:
`evince: error while loading shared libraries: libpangocairo-1.0.so.0: failed to map segment from shared object`
And this error continues with a different library if I then remove libpangocairo-1.0.so. I tried doing that through about 20 different libraries before I stopped trying to see when the issue would end.

Evidently, this issue has been seen before. On https://answers.launchpad.net/kathaikalam/+question/206392, the program was explicitly calling Evince to open the PDF file, so the developer fixed the issue by calling xpdf instead. However, since QDesktopServices opens a local file using the operating system's default program, I can't tell it not to use Evince.

So is there any way to get Evince to work with PyInstaller? Or any other workarounds? I thought about having my program determine if the OS is Ubuntu, and if so, not using QDesktopServices but instead explicitly use xpdf or some other program, but the issue there is that the user might not have that program installed. QDesktopServices is very nice in that it calls a program that's known to be present on the user's system.

I'm using Ubuntu 20.04.2 LTS, PySide2 5.15.2, and PyInstaller 4.2.

Efrem Braun

Efrem Braun

unread,
Mar 12, 2021, 9:52:22 AM3/12/21
to pyins...@googlegroups.com
(Sorry for yesterday's double message.)

I spent more time looking into this issue, and a workaround is given in https://github.com/pyinstaller/pyinstaller/issues/3668#issuecomment-428951753. Basically, I now test whether the OS is Linux, and if so, instead of calling `QDesktopServices.openUrl`, I follow the lengthy procedure given in that commented issue and finish by calling `subprocess.Popen(["xdg-open", "file.pdf", env=myEnv)`.

This workaround works for me for now. However, I expect other Qt developers may be unaware that their applications using QDesktopServices don't work in Linux unless they do a good job testing. And once I became aware of this issue, it still took me several hours to find this workaround. So I think this is a bug that should really be fixed. I mentioned this in https://github.com/pyinstaller/pyinstaller/issues/3668#issuecomment-797138475 and https://github.com/pyinstaller/pyinstaller/issues/2892#issuecomment-797140616.

Efrem Braun


--
You received this message because you are subscribed to a topic in the Google Groups "PyInstaller" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyinstaller/oKLmcV6nSe0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/0b927c78-dcac-44d9-91ce-e252bf63e8a9n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages