(venv) (base) sunyuhua@sunyuhua-HKF-WXX:~/PycharmProjects/fastApiProject/dist$ chmod 775 app 
(venv) (base) sunyuhua@sunyuhua-HKF-WXX:~/PycharmProjects/fastApiProject/dist$ ./app 
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: offscreen, linuxfb, vnc, minimalegl, minimal, wayland, xcb, wayland-egl, vkkhrdisplay.

已中止 (核心已转储)
(venv) (base) sunyuhua@sunyuhua-HKF-WXX:~/PycharmProjects/fastApiProject/dist$

这个错误通常是由于缺少某些依赖库导致的,特别是关于Qt平台插件 xcb。我们可以通过以下步骤来解决这个问题:

  1. 安装依赖库
    你需要确保系统中安装了 libxcb-xinerama0libxcb-cursor0,可以通过以下命令安装:
sudo apt-get install libxcb-xinerama0
sudo apt-get install libxcb-cursor0
  1. 重新生成可执行文件
    确保PyInstaller在打包时包含所有必要的库。可以使用以下命令重新生成可执行文件:
pyinstaller --onefile --add-binary /usr/lib/x86_64-linux-gnu/libxcb.so.1:. --add-binary /usr/lib/x86_64-linux-gnu/libxcb-xinerama.so.0:. hello_world.py

请注意,路径 /usr/lib/x86_64-linux-gnu/ 是常见的库路径,可能需要根据你的系统调整。

  1. 运行生成的可执行文件
    确保你在虚拟环境外运行可执行文件,这样可以避免依赖问题。退出虚拟环境并运行:
deactivate
./dist/hello_world

如果这些步骤仍然无法解决问题,你可以尝试设置 QT_DEBUG_PLUGINS 环境变量以获取更多调试信息:

export QT_DEBUG_PLUGINS=1
./dist/hello_world

ubuntu22.04开发PyQt6:Could not load the Qt platform plugin “xcb“ in ““ even though it was found._Qt