Help us understand the problem. What is going on with this article?

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

症状

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

環境

条件 内容
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のほうに入れてみる

結果:ダメ

解決法

仕方ないのでopencv-pythonをダウングレード。

pip uninstall opencv-python
pip install opencv-python=4.2.0

感想

バイトで複数台のマシンで発生した事案だったので試行錯誤した結果、3台目でようやく理解した。アホです。
Anacondaのせいかと思ってたけど彼は悪くなかった。だいたい原因はあいつのことが多いけど

tanipen
バイトでPythonを扱っています。記事は基本的に備忘録。Atcoder緑(Python)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした