相同点:两者都是QT与Python结合的桥梁;
不同点:PyQt的开发者是英国的“Riverbank Computing”公司,而PySide则是由Qt的开发公司诺基亚发布的,两者的主要区别主要是提供的授权方式不同:PyQt遵守GPLv3协议,而PySide则是LGPL协议,前者可以免费地用于自由软件的开发,而后者属于闭源商用。更详细资料可参考:
PySide2与PyQt5区别
在使用PySide2 或者 PyQt5 的过程中可能会出现以下错误:
根据给出的提示可以看出错误原因是系统找不到Qt平台的插件,解决方法则是将PySide2或者PyQt5的plugins目录加入到QT_QPA_PLATFORM_PLUGIN_PATH环境变量里面。
上面部分已经说了解决思路,具体的实施方式有以下两种:
-
添加启动代码【简单重复】:
import PySide2
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
如果是PyQt5则需要修改启动代码为:
import qt5_applications
dirname = os.path.dirname(qt5_applications.__file__)
plugin_path = os.path.join(dirname, 'Qt', 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
在引入各类包的后面插入上述代码:
-
修改配置文件【一劳永逸】
如果不想每次在代码前添加上述代码,可以修改PySide2的初始化文件"c:\users\XXX.virtualenvs\pyqt5-3bre18dc\lib\site-packages\PySide2_
init
_.py" ,在下图位置添加上述代码即可:
对于PyQt5则需要手动添加PyQt的环境变量:
如需快速查找使用pip命令安装的包的位置可以使用
pip show model_name
:
在使用PySide2或者PyQt5的过程中,可能会出现“ This application failed to start because it could not find or load the Qt platfor m plugin "windows" in "". ” 或者 “qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""”错误,下面针对这种错误给出解决方法。
如何建立
Qt
从下载
Qt
来源(
qt
-everywhere-opensource-src-5.9.5.tar.xz )并将其解压缩到某个地方。
mkdir /home/nizovn/webos/
qt5
/
qt5
.9
tar xvf
qt
-everywhere-opensource-src-5.9.5.tar.xz -C /home/nizovn/webos/
qt5
/
qt5
.9
从下载并解压缩gcc跨工具链( gcc-linaro-4.8-2015.06-x86_64_arm-linux-gnueabi.tar.xz )。
tar xvf gcc-linaro-4.8-2015.06-x86_64_arm-linux-gnueabi.tar.xz -C /home/nizovn/webos/
qt5
/
qt5
.9
2.在环境变量中添加
变量名:
QT
_
QPA
_
PLATFORM
_
PLUGIN
_PATH
变量值:D:\Anaconda3\Lib\site-packages\PySide2\
plugin
s
3.注销重新登录
windows
系统
4.打开相关编译器的cmd
win键+s
cd /d 你的exe所在目录
windeploy
qt
xxxxxxx.exe
重新运行即可
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon)
Target compiler: gcc 6.3.1
Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports stl
Build options:
Mode ................................... release
Optimize release build for size ........ no
Building shared libraries .............. yes
Using C standard ....................... C11
Using C++ standard ..................... C++14
Using ccache ........................... no
Using gold linker ...................... yes
Using new DTAGS ........................ yes
Using precompiled headers .............. yes
Using LTCG ............................. no
Target compiler supports:
NEON ................................. yes
Build parts ............................ libs
Qt
modules and options:
Qt
Concurrent .......................... yes
Qt
D-Bus ............................... yes
Qt
D-Bus directly linked to libdbus .... no
Qt
Gui ................................. yes
Qt
Network ............................. yes
Qt
Sql ................................. yes
Qt
Testlib ............................. yes
Qt
Widgets ............................. yes
Qt
Xml ................................. yes
Support enabled for:
Using pkg-config ....................... yes
udev ................................... no
Using system zlib ...................... yes
Qt
Core:
DoubleConversion ....................... yes
Using system DoubleConversion ........ no
GLib ................................... no
iconv .................................. yes
ICU .................................... no
Tracing backend ........................
Logging backends:
journald ............................. no
syslog ............................... no
slog2 ................................ no
Using system PCRE2 ..................... no
Qt
Network:
getifaddrs() ........................... yes
IPv6 ifname ............................ yes
libproxy ............................... no
Linux AF_NETLINK ....................... yes
OpenSSL ................................ yes
Qt
directly linked to OpenSSL ........ no
OpenSSL 1.1 ............................ no
DTLS ................................... yes
SCTP ................................... no
Use system proxies ..................... yes
Qt
Gui:
Accessibility .......................... yes
FreeType ............................... yes
Using system FreeType ................ no
HarfBuzz ............................... yes
Using system HarfBuzz ................ no
Fontconfig ............................. no
Image formats:
GIF .................................. yes
ICO .................................. yes
JPEG ................................. yes
Using system libjpeg ............... yes
PNG .................................. yes
Using system libpng ................ no
EGL .................................... no
OpenVG ................................. no
OpenGL:
Desktop OpenGL ....................... no
OpenGL ES 2.0 ........................ no
OpenGL ES 3.0 ........................ no
OpenGL ES 3.1 ........................ no
OpenGL ES 3.2 ........................ no
Vulkan ................................. no
Session Management ..................... yes
Features used by
QPA
backends:
evdev .................................. yes
libinput ............................... no
INTEGRITY HID .......................... no
mtdev .................................. no
tslib .................................. no
xkbcommon .............................. no
X11 specific:
XLib ................................. no
EGL on X11 ........................... no
QPA
backends:
DirectFB ............................... no
EGLFS .................................. no
LinuxFB ................................ yes
VNC .................................... yes
Mir client ............................. no
Qt
Sql:
SQL item models ........................ yes
Qt
Widgets:
GTK+ ................................... no
Styles ................................. Fusion
Windows
Qt
PrintSupport:
CUPS ................................... no
Qt
Sql Drivers:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... no
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt
Testlib:
Tester for item models ................. yes
Qt
SerialBus:
Socket CAN ............................. yes
Socket CAN FD .......................... yes
Qt
QML:
QML network support .................... yes
QML debugging and profiling support .... yes
QML sequence object .................... yes
QML list model ......................... yes
QML XML http request ................... yes
QML Locale ............................. yes
QML delegate model ..................... yes
Qt
Quick:
Direct3D 12 ............................ no
AnimatedImage item ..................... yes
Canvas item ............................ yes
Support for
Qt
Quick Designer .......... yes
Flipable item .......................... yes
GridView item .......................... yes
ListView item .......................... yes
TableView item ......................... yes
Path support ........................... yes
PathView item .......................... yes
Positioner items ....................... yes
Repeater item .......................... yes
ShaderEffect item ...................... yes
Sprite item ............................ yes
Qt
Scxml:
ECMAScript data model for
Qt
Scxml ...... yes
Qt
Gamepad:
SDL2 ................................... no
Qt
3D:
Assimp ................................. yes
System Assimp .......................... no
Output
Qt
3D Job traces ................. no
Output
Qt
3D GL traces .................. no
Use SSE2 instructions .................. no
Use AVX2 instructions .................. no
Aspects:
Render aspect ........................ yes
Input aspect ......................... yes
Logic aspect ......................... yes
Animation aspect ..................... yes
Extras aspect ........................ yes
Qt
3D Renderers:
OpenGL Renderer ........................ yes
Qt
3D GeometryLoaders:
Autodesk FBX ........................... no
Qt
Wayland Client ........................ no
Qt
Wayland Compositor .................... no
Qt
Bluetooth:
BlueZ .................................. no
BlueZ Low Energy ....................... no
Linux Crypto API ....................... no
WinRT Bluetooth API (desktop & UWP) .... no
Qt
Sensors:
sensorfw ............................... no
Qt
Quick Controls 2:
Styles ................................. Default Fusion Imagine Material Universal
Qt
Quick Templates 2:
Hover support .......................... yes
Multi-touch support .................... yes
Qt
Positioning:
Gypsy GPS Daemon ....................... no
WinRT Geolocation API .................. no
Qt
Location:
Qt
.labs.location experimental QML
plugin
. yes
Geoservice
plugin
s:
OpenStreetMap ........................ yes
HERE ................................. yes
Esri ................................. yes
Mapbox ............................... yes
MapboxGL ............................. no
Itemsoverlay ......................... yes
Qt
XmlPatterns:
XML schema support ..................... yes
Qt
Multimedia:
ALSA ................................... no
GStreamer 1.0 .......................... no
GStreamer 0.10 ......................... no
Video for Linux ........................ yes
OpenAL ................................. no
PulseAudio ............................. no
Resource Policy (libresource
qt5
) ....... no
Windows
Audio Services ................. no
DirectShow ............................. no
Windows
Media Foundation ............... no
Qt
Tools:
QDoc ................................... no
Qt
WebEngine:
Embedded build ......................... yes
Pepper
Plugin
s ......................... no
Printing and PDF ....................... no
Proprietary Codecs ..................... no
Spellchecker ........................... yes
Native Spellchecker .................... no
WebRTC ................................. no
Use System Ninja ....................... no
Geolocation ............................ yes
WebChannel support ..................... yes
Use v8 snapshot ........................ yes
Kerberos Authentication ................ no
Building v8 snapshot supported ......... yes
Use ALSA ............................... no
Use PulseAudio ......................... no
Optional system libraries used:
re2 .................................. no
icu .................................. no
libwebp, libwebpmux and libwebpdemux . no
opus ................................. no
ffmpeg ............................... no
libvpx ............................... no
snappy ............................... no
glib ................................. no
zlib ................................. yes
minizip .............................. no
libevent ............................. no
jsoncpp .............................. no
protobuf ............................. no
libxml2 and libxslt .................. no
lcms2 ................................ no
png .................................. no
JPEG ................................. no
harfbuzz ............................. no
freetype ............................. no
x11 .................................. no
Required system libraries:
fontconfig ........................... no
dbus ................................. no
nss .................................. no
khr .................................. no
glibc ................................ yes
Required system libraries for
qpa
-xcb:
libdrm ............................... no
xcomposite ........................... no
xcursor .............................. no
xi ................................... no
xrandr ............................... no
xtst ................................. no
Note: Also available for Linux: linux-clang linux-icc
在 import Py
Qt5
并使用时,出现以下
错误
:
qt
.
qpa
.
plugin
: Could not find the
Qt
platform
plugin
“
windows
” in “”
This application failed to start because no
Qt
platform
plugin
could be initialized. Reinstalling the application may fix this problem.
Py
Qt5
== 5.15.4
py
qt5
-tools == 5.15.4.3.2
Py
Qt5
及py
qt5
-tools全部按照教程使用pip 安装(中途报了一个error,将依赖包click从8.*降级至7.0,不过这一步应该没什么影响)
出现的问题
运行如下实例代码后出现了Could not find the
Qt
platform
plugin
python
代码很简短,不像C++等要写几百行代码,但其实你调用的模块,底层都是用C/C++写的
如果imshow出现
qt
.
qpa
.
plugin
: Could not find the
Qt
platform
plugin
“cocoa” in “”的报错,请看:Stackoverflow
解决
方案
请提前安装好opencv-
python
库
由于历史原因opencv-
python
库使用时只能叫cv2
人脸检测效果图
python
完整代码
识别静态图片
# 导入opencv-
python
库
import cv2
picName = input("请输入你要识别人类的图片名称(如:pi
很抱歉,我不太了解这个问题。
很抱歉,我无法理解您的问题。请能够更清楚地表达您的问题,我会尽力帮助您。
很抱歉,我无法理解您的问题。这个
错误
提示意味着程序找不到
Qt
平台插件“
windows
”,它应该在某个地方被定义或者安装在程序的运行路径中。
有几种可能的
解决
方案:
1. 确保你的程序路径中包含了
Qt
平台插件的路径。在
Qt
安装目录下,可以找到一个名为“
platform
s”的文件夹,其中包含了各个平台的插件,例如“q
windows
.dll”文件是用于
Windows
系统的插件。将这些插件文件夹复制到你的程序路径中,或者将它们添加到系统路径中,可能会
解决
这个问题。
2. 可能是
Qt
版本不兼容或者
Qt
库没有正确安装。检查你的程序使用的
Qt
库版本是否正确,并且在系统中安装了相应版本的
Qt
库。尝试重新安装
Qt
并确保安装路径和环境变量正确配置。
3. 也有可能是
Qt
库没有被正确链接到程序中。检查你的程序链接选项是否正确,并且确保
Qt
库文件在程序的运行路径中。
希望这些
解决
方案可以帮助你
解决
这个问题。