3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【備忘録】pyqtとopencvでQtのライブラリが競合した場合の対処法

Last updated at Posted at 2020-07-19

2021/02/25 追記:知らない間にopencv-python最近のアップデートで修正されたようです。

症状

概要はタイトル通り。詳細は以下の通り。

環境

条件 内容
OS macOS Catalina 10.15.6
python環境 pyenv + Anaconda2020-02/miniconda3-latest
- Pyqt5 5.15.0
- opencv-python 4.3.0

内容

opencv-pythonPyQt5を同時使用するプログラムを実行したところ、長ったらしいエラーメッセージと共に強制終了。

objc[54311]: ClassQMacAutoReleasePoolTracker is implemented in bot /Users/hogehoge/opt/anaconda3/lib/python3.7/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (fugafuga) and /Users/hogehoge/opt/anaconda3/lib/python3.7/site-packages/cv2/.dylibs/QtCore (fugafuga). One of the two will be used. Which one is undefined.
objc[54311]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE (同上).
objc[54311]: Class KeyValueObserver (同上).
objc[54311]: Class RunLoopModeTracker (同上).
(中略)

You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
qt.qpa.plugin: Could not load the Qt platform plugin "cocoa" in "/Users/hogehoge/opt/anaconda3/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.

Available platform plugins are: cocoa, minimal, offscreen, webgl.

もうまずこのメッセージ量で諦めかけた。けどやらないわけにはいかなかった。

原因

とりあえずこいつが脳死で参照しているopencvのQtのpluginフォルダを見に行ったらほぼ空っぽ。importの順番かアルファベット順かはちゃんと確認してないけど、こいつが原因のようで。

試行錯誤

参考: https://qiita.com/sukoppu1102/items/f5c00b520da0fa5d2ff3

windowsでの不具合だが、エラー箇所が似ている。試しにQT_PLUGIN_PATHをPyQtのほうに入れてみる

結果:ダメ

解決法

(2021/02/25修正)
最近修正されたようで、最新版にアップデートすると問題なく動作します。

pip install -U opencv-python
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?