pop-os / pop

A project for managing all Pop!_OS sources
https://system76.com/pop
2.43k stars 84 forks source link

Programs using PyQt6 throw error "Could not load a pixbuf from icon theme." when using native UI, cause core dump #3270

Open NickleDave opened 4 months ago

NickleDave commented 4 months ago

Distribution (run cat /etc/os-release):

NAME="Pop!_OS" VERSION="22.04 LTS" ID=pop ID_LIKE="ubuntu debian" PRETTY_NAME="Pop!_OS 22.04 LTS" VERSION_ID="22.04" HOME_URL="https://pop.system76.com" SUPPORT_URL="https://support.system76.com" BUG_REPORT_URL="https://github.com/pop-os/pop/issues" PRIVACY_POLICY_URL="https://system76.com/privacy" VERSION_CODENAME=jammy UBUNTU_CODENAME=jammy LOGO=distributor-logo-pop-os

Related Application and/or Package Version (run apt policy $PACKAGE NAME):

N/A

Issue/Bug Description:

Python code that uses the PyQt6 library throws an error and causes a core dump when trying to load system native UI like an "open directory" dialog

I think the underlying cause is whatever's causing the bug in #2911 (and possibly #3224?)

Steps to reproduce (if you know):

Here is an MRE in the form of a Python script. I'll explain how to run below to reproduce the bug.

from __future__ import annotations

import sys

from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import (
    QApplication,
    QFileDialog,
    QMainWindow,
)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("app")

        menu = self.menuBar()
        file_menu = menu.addMenu("&File")
        open_folder_action = QAction("Open folder", self)
        open_folder_action.triggered.connect(self.open_folder)
        file_menu.addAction(open_folder_action)

    def open_folder(self):
        folder_path = QFileDialog.getExistingDirectory(
            parent=self,
            caption="Open folder",
            directory="",  # current directory
        )
        return folder_path

app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()

To run:

Create a Python virtual environment (I'm using virtualenv, installed with pipx, installed with brew)

$ brew install pipx
$ pipx install virtualenv
$ virtualenv ./.venv -p 3.10
$ . .venv/bin/activate
(.venv) $ pip install PyQt6

Save the MRE above in app.py Run the MRE by doing app.py by doing python app.py.

Clicking on Menu > Open Folder in the running app.py should produce:

(python:591124): Gtk-WARNING **: 22:41:11.208: Could not load a pixbuf from icon theme.
This may indicate that pixbuf loaders or the mime database could not be found.
**
Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/share/icons/Pop/16x16/status/image-missing.svg: Unable to load image-loading module: /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: libicuuc.so.72: cannot open shared object file: No such file or directory (gdk-pixbuf-error-quark, 5)
Bail out! Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/share/icons/Pop/16x16/status/image-missing.svg: Unable to load image-loading module: /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: libicuuc.so.72: cannot open shared object file: No such file or directory (gdk-pixbuf-error-quark, 5)
[1]    591124 IOT instruction (core dumped)  python app.py

Expected behavior:

PyQt6-based programs run without error.

Other Notes: Related to #2911 and possibly #3224

NickleDave commented 4 months ago

fwiw I don't get this error on another machine (a deep learning rig I assembled, not a laptop bought from System76), even though I have the same distribution installed on it (cuz Pop-OS does such a good job of dealing with Nvidia drivers :slightly_smiling_face: )

NAME="Pop!_OS"
VERSION="22.04 LTS"
ID=pop
ID_LIKE="ubuntu debian"
PRETTY_NAME="Pop!_OS 22.04 LTS"
VERSION_ID="22.04"
HOME_URL="https://pop.system76.com"
SUPPORT_URL="https://support.system76.com"
BUG_REPORT_URL="https://github.com/pop-os/pop/issues"
PRIVACY_POLICY_URL="https://system76.com/privacy"
VERSION_CODENAME=jammy
UBUNTU_CODENAME=jammy
LOGO=distributor-logo-pop-os

I instead get another error

qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: wayland, minimal, offscreen, vnc, vkkhrdisplay, linuxfb, xcb, wayland-egl, minimalegl, eglfs.

that I was able to fix with the magic incantation sudo apt-get install -y libxcb-cursor-dev as suggested here: https://forum.qt.io/topic/145196/could-not-load-the-qt-platform-plugin-xcb-in-even-though-it-was-found/7

Just adding that in case it helps hunt down the source of the issue