问题
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
回答1:
After 20 hours of research, I solved the problem by compiling from source. I used this tutorial to install opencv on Anaconda Environmnent
来源:https://stackoverflow.com/questions/50783047/how-to-install-libavformat-so-56-along-with-libavformat-so-57