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

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

  • 一、PyQt5与Qt designer安装
  • 二、Vscode中PyQt5插件安装
  • 三、运行MainWindow.py可能会遇到链接不到库的情况


一、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是用户名称

你可能感兴趣的:(linux,vscode,qt)