Deepin下搭建pyqt5开发环境——基于vscode

本文介绍了如何在Deepin操作系统中搭建PyQT5的开发环境,主要步骤包括安装pyqt5和QT5开发工具,然后在VSCode中安装PYQT Integration插件并配置其设置。可能会遇到的错误包括因安装多个pyqt5版本导致的 xcb 问题,以及使用Pyinstaller打包后的程序运行问题,解决方案是对pyqt5进行卸载和创建软链接修复。此外,还提到了如何通过设置环境变量来追踪插件问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.安装pyqt5

sudo apt-get install pyqt5*

2.安装QT5开发工具,里面包含了Qt Designer等工具

sudo apt-get install qttools5-dev-tools

3.打开vscode,搜索pyqt,安装PYQT Integration插件

4.点击小齿轮-->扩展设置,对PYQT Integration插件进行设置

5.在Pyqt-integration › Qtdesigner: Path中,增加QT designer的路径

/usr/lib/x86_64-linux-gnu/qt5/bin/designer

 

这样完成了对Deepin下pyqt5开发环境的搭建

可能出现的错误提示:

错误提示1

Error: Command failed: "pyuic5" -p "/home/nexfia/Documents/PyQt5 Project/PDFDecryptionTool/WinUI.ui"

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: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted

错误提示2

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: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

错误提示1是使用PYQT Integration插件对.ui文件进行预览时提示的。

错误提示2时python程序导入了pyqt5,运行程序时提示的

这2个错误的原因在于你装了多个pyqt5

一个可能是使用 pip 安装了一个

pip3 install pyqt5

另一个可能是使用我上面的命令安装了一个

sudo apt-get install pyqt5*

导致不知道用那个xcb

解决方法是将使用pip安装的pyqt5卸载掉

pip3 uninstall pyqt5

其他可能出现的错误

打不开使用Pyinstaller打包的pyqt5程序,但在vscode调试时能正常运行,在终端运行显示

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: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

已放弃

这个是QT5的bug,原因是在Debian系Linux中,只有libxcb-util.so.0,而没有libxcb-util.so.1。

使用以下命令,通过创建软链接创建修复

cd /usr/lib/x86_64-linux-gnu
sudo ln -s libxcb-util.so.0  libxcb-util.so.1

参考

老牛知点所以然-Qt安装后一行命令解决:libxcb-util.so.1 => not found_libxcb-util.so.1 => not found-优快云博客

追踪插件的问题

为了方便追踪插件的问题,我们添加一下环境变量。

首先安装gedit

sudo apt install gedit

打开终端,输入以下命令

gedit ~/.bashrc

在最末尾中增加一行

export QT_DEBUG_PLUGINS=1

保存。在终端中输入以下命令使得修改生效

source ~/.bashrc

这样我们在程序运行时就会获得比较详细的插件Debug信息

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值