5
6

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 5 years have passed since last update.

Python3+OpenCVがうまくいかない。。。

Last updated at Posted at 2018-08-03

#Raspberry pi 3B(Raspbian Stretch)にOpenCVをインストールしたが

Raspbian StretchでPython3+OPENCVをインストールした際にうまく行かず、試行錯誤し解決した結果を以下に記載。

インストール済OSを確認
OSのバージョンチェック
$ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
(以下省略)
OpenCV関連のインストール
OpenCVのインストール
$ sudo apt-get install libopencv-dev
$ sudo apt-get install python-opencv
Python3で動かしてみる
python3
$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.5/site-packages/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: libQtTest.so.4: cannot open shared object file: No such file or directory
ここでエラーが出る。。。Python2でテストしてみる。
Python2でテスト
$ python2
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.1'

###### Python2ではエラーはでない。本家サイトで同じ内容のPOSTを発見

ここでエラーがでるのでpip3でのインストールとエラーの原因となっている「libQtTest.so.4」の対策をしてみる。
対策
$ sudo pip3 install opencv-python
$ sudo apt-get install libqt4-test
再びPython3でテスト
Python3で再トライ
$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.2'

######無事に動いた。

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?