安裝完opencv-contrib-python後 import cv2
時出現:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.7/site-packages/cv2/__init__.py", line 3, in <module> from .cv2 import * ImportError: libhdf5_serial.so.103: cannot open shared object file: No such file or directory
— — — — — — 解決- — — — — — —
- Step1:
到 cv2
路徑下
>> cd /usr/local/lib/python3.7/site-packages/cv2
找到 cv2.cpython-37m-arm-linux-gnueabihf.so
- Step2:
尋找未安裝的套件
>> ldd cv2.cpython-37m-arm-linux-gnueabihf.so | grep "not found"
Out::
libQtTest.so.4 => not found
- Step3:
安裝 apt-file
>> sudo apt install apt-file
- Step4:
搜尋套件:
>> apt-file search libQtTest.so.4
Out::(冒號前面是套件名稱)
libqt4-test: /usr/lib/arm-linux-gnueabihf/libQtTest.so.4
libqt4-test: /usr/lib/arm-linux-gnueabihf/libQtTest.so.4.8
libqt4-test: /usr/lib/arm-linux-gnueabihf/libQtTest.so.4.8.7
- Step5:
安裝缺少的套件:
>> sudo apt install libqt-4-test
直到所有套件都安裝即可
— — — — — — — — — — — — — — — — — — -
- 若出現:
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: /usr/local/lib/python3.7/site-packages/cv2/cv2.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_fetch_add_8
則可嘗試:
pip install opencv-python==3.4.6.27