在我的树莓派 4(全新安装)上编译并安装 opencv 4.1.1 后,我在尝试导入 cv2 时收到了类似的消息:
(cv) pi@raspberrypi:~ $ python
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_reg.so.3.3: cannot open shared object file: No such file or directory
>>>
我尝试了this solution,但没有成功,所以我以一种“肮脏”的方式进行了操作:
我运行了命令
(cv) pi@raspberrypi:~ $ sudo ldconfig -v
我有一堆线。重要的:
...
/usr/local/lib:
....
libopencv_reg.so.4.1 -> libopencv_reg.so.4.1.1
...
然后我创建了一个符号链接:
(cv) pi@raspberrypi:~ $ cd /usr/local/lib
(cv) pi@raspberrypi:/usr/local/lib $ sudo ln -s libopencv_reg.so.4.1.1 libopencv_reg.so.3.3
终于成功了!
(cv) pi@raspberrypi:~ $ python
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.1'
>>>
重新启动我的树莓派并再次导入 cv2 后,新的 .so 文件“丢失”了,所以我对 '/usr/local/lib' 中的所有其他 libopencv_*.so.4.1.1 文件重复了最后一步
sudo ln -s libopencv_<<other_lib>>.so.4.1.1 libopencv_<<other_lib>>.so.3.3