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信息