0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenCVスクリプト起動時にQt platform plugin "xcb"エラー

Last updated at Posted at 2025-02-01

OpenCVをimportしたpythonスクリプトを実行すると

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ubuntu/.pyenv/versions/taichofu_env/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.

というエラーが出て、いろいろ対策を試みると

ImportError: /home/???????/miniconda3/envs/ros/lib/python3.10/site-packages/PyQt5/QtWidgets.abi3.so: undefined symbol: _ZdlPvm, version Qt_5

というエラーに落ち着いたりする。
検索すると多くのサイトがヒットします。私の場合それらの方法では解決しませんでした。参考にしたのは次のサイト
Problem with PyQT5 in Ubuntu 22.04 not fount _ZdaPvm
condaの仮想環境のQt5パッケージを/usr/libのもので置き換えてしまう方法です。
参照しているサイトの環境依存の場所を自分の環境に読み替えて

(base) ~/miniconda3/envs/ros/lib/python3.10/site-packages$ mv PyQt5 __PyQt5
$ mv PyQt5 __PyQt5
(base) ~/miniconda3/envs/ros/lib/python3.10/site-packages$ ln -s /usr/lib/python3/dist-packages/PyQt5 .

で解決しました。
おそらくconda環境のPyQt5のバージョン

(ros) $ pip list | grep Qt
PyQt5                                5.15.6
PyQt5-Qt5                            5.15.16
PyQt5_sip                            12.16.1

とホストにインストールしたPyQt5の関連ライブラリのバージョン

$ dpkg -l | grep pyqt5
ii  pyqt5-dev                                         5.15.6+dfsg-1ubuntu3                    all          Development files for PyQt5
ii  pyqt5-dev-tools                                   5.15.6+dfsg-1ubuntu3                    amd64        Development tools for PyQt5
ii  python3-pyqt5                                     5.15.6+dfsg-1ubuntu3                    amd64        Python 3 bindings for Qt5
   ・・・・・・

の違いが原因の一つと推測しますが、動いてしまったのでここまでです。
conda環境を使っていて、同様のトラブルでお悩みの方は試してみてください。リンクを修正する前にオリジナル(.../site-packages/PyQt5)のバックアップをわすれずに

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?