You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu虚拟环境中使用PyQt5时出现xcb插件缺失错误

Ubuntu虚拟环境中PyQt5启动报错的解决办法

针对虚拟环境运行PyQt5时出现的qt.qpa.plugin: Could not find the Qt platform plugin "xcb"错误,可按以下步骤解决:

  • 安装系统层面的xcb依赖库
    执行以下命令补全系统依赖:

    sudo apt-get install libxcb-xinerama0 libxcb-cursor0 libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxcb-xkb1
    
  • 关联系统Qt平台插件到虚拟环境
    方法一:临时设置环境变量(激活虚拟环境后执行)

    export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/
    

    若想永久生效,可将上述命令添加到虚拟环境目录下的bin/activate文件末尾,每次激活虚拟环境时自动加载。

    方法二:创建软链接
    找到虚拟环境中PyQt5的插件目录(替换your_venv为你的虚拟环境名,python3.x为对应版本):

    cd ~/your_venv/lib/python3.x/site-packages/PyQt5/Qt5/plugins/
    ln -s /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/ platforms
    
  • 重新安装PyQt5(上述方法无效时尝试)

    pip uninstall PyQt5 -y
    pip install PyQt5 --no-cache-dir
    

内容的提问来源于stack exchange,提问作者Yusuf Kiriş

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 08:50:23