環境
- Python 3.7.7
- Qt (PySide2) 5.15.0
- OpenCV (opencv-python) 4.3.0.36
エラー内容
元々はPySide2を使って画像を表示するアプリケーションを作成していたのですが、表示画像を補正する必要が出てきたので opencv-python をインストールしました。直後に下記エラーが発生。
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/***/.local/share/virtualenvs/***/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.
訳
Qtバイナリの2つのセットを同じプロセスにロードしている可能性があります。 すべてのプラグインが正しいQtバイナリに対してコンパイルされていることを確認してください。 DYLD_PRINT_LIBRARIES = 1をエクスポートし、1セットのバイナリのみがロードされていることを確認します。
qt.qpa.plugin:「/Users/***/.local/share/virtualenvs/***/lib/python3.7/site-packages/cv2/qt/」にあるQtプラットフォームプラグイン「cocoa」を読み込めませんでした プラグイン」が見つかりましたが、
Qtプラットフォームプラグインを初期化できなかったため、このアプリケーションを開始できませんでした。 アプリケーションを再インストールすると、この問題が解決する場合があります。
解決方法
どうやら双方にGUI機能が含まれているから競合しているらしい?なので、
$ pip uninstall -y opencv-pythonopencv-python をアンインストールして、
$ pip install opencv-python-headlessGUI機能を含まない、OpenCVのヘッドレス版をインストールすると正常に動作しました。
![QtとOpenCVの両方をインストールするとエラーが発生する[Python]](https://images.microcms-assets.io/assets/dc2e127498c741209a393197e390fced/0b1d0b3396624ad48d58b42cb4d2a4be/eye_catch.png)