Linux环境下在Vscode中安装和设置PyQt5插件


一、PyQt5与Qt designer安装

创建并进入环境,然后安装PyQt5

pip install pyqt5
pip install pyqt5-tools

测试是否安装成功

pip show pyqt5

安装Qt designer

sudo apt-get install qttools5-dev
sudo apt-get install qttools5-dev-tools

测试是否安装成功,直接运行

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

二、Vscode中PyQt5插件安装

1、在Vscode插件查找中搜索pyqt integration插件并安装
2、File >> Preferences >> Settings,搜索pyqt integration
3、PyQt-integration >> Qtdesigner:path里面输入designer的路径,我的路径是/usr/lib/x86_64-linux-gnu/qt5/bin/designer
4、PyQt-integration >> Pyuic:cmd里面输入designer的路径,我的路径是/home/xxxx/anaconda3/envs/pyrs-py3-7/bin/pyuic5

测试是否安装成功

1、设置好之后在vscode编辑器的左侧文件目录栏空白位置右键,选择PYQT:New Form即可打开Qt Designer
2、编辑保存.ui之后,右键该文件,选择PYQT:Compile Form,即可将.ui转为.py

三、运行MainWindow.py可能会遇到链接不到库的情况

出现以下错误提示

loaded library "/home/xxxx/anaconda3/envs/pyrs-py3-7/lib/python3.7/site-packages/cv2/qt/plugins/platforms/libqxcb.so"
QObject::moveToThread: Current thread (0x558089c48730) is not the object's thread (0x55808bdeb1a0).
Cannot move to target thread (0x558089c48730)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/xxxx/anaconda3/envs/pyrs-py3-7/lib/python3.7/site-packages/cv2/qt/plugins" 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.

需要在程序之前添加临时的环境变量

import os
dirname = '/home/xxxx/anaconda3/envs/pyrs-py3-7/lib/python3.7/site-packages/cv2/qt'
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path

其中xxxx是用户名称

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值