天天看點

python qt 有用嗎_【環境踩坑】pycharm使用qt時報錯

之前已經安裝好qt運作代碼也沒問題,後來移動了一下環境和代碼位置,再運作就會報錯如下:

報錯:

Cannot move to target thread (0x257a660)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/data/xx/xx/venv/lib/python3.6/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.

Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

解決方法:需要把qt相關庫libqxcb.so添加到環境變量中

具體操作的話就是在運作的.py檔案前添加以下内容:

envpath = '/data/xx/xx/venv/lib/python3.6/site-packages/cv2/qt/plugins/platforms'

os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = envpath

python qt 有用嗎_【環境踩坑】pycharm使用qt時報錯

試試吧~~