0

I used pip to install opencv3 with the following command on an Anaconda virtual environment.

install opencv-python

I successfully installed it because I can see the package in pip list.

(olfatf)rover@rover_pi:/usr/lib/arm-linux-gnueabihf $ pip list | grep opencv
opencv-python          3.4.0.14  

However, when I do import cv2, I get the following error:

(olfatf)rover@rover_pi:/usr/lib/arm-linux-gnueabihf $ python
Python 3.4.3 |Continuum Analytics, Inc.| (default, Aug 21 2015, 00:53:08) 
[GCC 4.6.3] 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/.conda/envs/olfatf/lib/python3.4/site-packages/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: libavformat.so.56: cannot open shared object file: No such file or directory

I checked the /usr/lib/arm-linux-gnueabihf directory and I found:

(olfatf)rover@rover_pi:/usr/lib/arm-linux-gnueabihf $ ls | grep libavformat
libavformat.a
libavformat.so
libavformat.so.57
libavformat.so.57.56.101

I you can see there, I have the version 57 but the version 56 is missing. I did research online and people suggested that I should install libavformat-dev

(olfatf)rover@rover_pi:/usr/lib/arm-linux-gnueabihf $ sudo apt-get install libavformat-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libavformat-dev is already the newest version (7:3.2.10-1~deb9u1+rpt1).

But it says that the package already exists. I also tried installing ffmpeg.

(olfatf)rover@rover_pi:/usr/lib/arm-linux-gnueabihf $ sudo apt-get install ffmpeg
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ffmpeg is already the newest version (7:3.2.10-1~deb9u1+rpt1).

But it says that the package already exists.

How to get the 56 version? I use Raspberry Pi Strech

0
  1. If you are using Python3 you should use pip3
  2. If typing python produces Python 3.4.3 you have broken your system, with unpredictable consequences.
  3. Raspbian Stretch comes with Python 3.5.3 installed

You should try a fresh installation using standard settings.

0

Do you need the anaconda environment? You can setup the connections between python and opencv without anaconda.

When I went to install opencv on the Raspberry Pi. I followed the tutorial from the pyimagesearch website.

Lots to prepare (pulled from the tutorial)

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev python3-dev

All this should give you what you need. Also to note, if you don't want the virtual environments that the tutorial setup, then you can ignore that part. Everything should work fine.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.