ubuntu import cv2 报错 ImportError: libopencv_ml.so.4.0

环境:opencv3.4.3 python2.7

import cv2
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python2.7/site-packages/cv2/init.py”, line 89, in
bootstrap()
File “/usr/local/lib/python2.7/site-packages/cv2/init.py”, line 79, in bootstrap
import cv2
ImportError: libopencv_ml.so.4.0: cannot open shared object file: No such file or directory

解决方法:
将/usr/local/lib/python2.7/dist-packages/cv2.so文件复制到/usr/local/lib/python2.7/dist-packages/cv2/python-2.7路径下
前提:删除路径下本来的cv2.so(不放心的话可以先留个备份)

sudo rm -rf /usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so

然后复制:

cd /usr/local/lib/python2.7/dist-packages
sudo cp cv2.so /usr/local/lib/python2.7/dist-packages/cv2/python-2.7

参考博客:https://blog.csdn.net/iSleepyPig/article/details/89552537

你可能感兴趣的:(opencv,python)