今天在安装树莓派版OpenCV opencv-python 时遇到各种错误
我使用的是树莓派zero 最新固件 在安装opencv时出现了各种莫名其妙的错误
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
opencv-contrib-python from https://www.piwheels.org/simple/opencv-contrib-python/opencv_contrib_python-3.4.3.18-cp37-cp37m-linux_armv6l.whl#sha256=3095eaade88d84d93ae0d35878d877a73561e1192fbf99bde2f1d3c5daf4dda3:
Expected sha256 3095eaade88d84d93ae0d35878d877a73561e1192fbf99bde2f1d3c5daf4dda3
Got 52f330a942637ce7e52930f28b3c6591b90b901f30d0a3cc88a3491873813f65
这个MD5校验错误可能是服务器被劫持了或者是其他原因,没办法
按照报错原因直接去pip官网下这个whl就好了
下下来直接pip安装就可以了
sudo pip3 install opencv_contrib_python-3.4.3.18-cp37-cp37m-linux_armv6l.whl
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "", line 1, in
File "/home/pi/.local/lib/python3.7/site-packages/cv2/__init__.py", line 3, in
from .cv2 import *
ImportError: libImath-2_2.so.23: cannot open shared object file: No such file or directory
这个万恶之源,libImath-2_2.so.23 公共库运行缺失
开始找这个库是哪里的 https://testerhome.com/topics/15593?locale=zh-CN 发现这个包叫libilmbase22 ,但是实际上找不到这个库名
后再Debian上找到类似的包名为libilmbase12,里面有一个libImath-2_2.so.12 看名字就是!开搞
更新apt源,以及apt update
deb http://ftp.de.debian.org/debian stretch main
然后就可以运行
sudo apt-get install libilmbase12
这里如果还是不行的话,可以去debian官网下载这个包,注意树莓派的架构是armhf
https://packages.debian.org/stretch/armhf/libilmbase12/download
下载完成后解包安装
sudo dpkg -i libilmbase12_2.2.0-12_armhf.deb
到这一步还不行,因为版本号不一样,要求的是23,而我们的是12,所有我们要进到目录更改文件名
/usr/lib/arm-linux-gnueabihf
cp libImath-2_2.so.12 libImath-2_2.so.23
这个问题终于搞定了
ImportError: libhdf5_serial.so.103: cannot open shared object file: No such file or directory
sudo apt-get install libhdf5-serial-dev
ImportError: libIlmImf-2_2.so.23: cannot open shared object file: No such file or directory
sudo apt-get install libopenexr-dev
ImportError: libgstbase-1.0.so.0: cannot open shared object file: No such file or directory
sudo apt-get install libgstreamer1.0-0
sudo apt-get install libgstreamer-plugins-base1.0-0
终于完事了!搞了一天