这里有一个Dockerfile:
FROM python:3.10
RUN apt update
RUN apt install -y libopencv-dev python3-opencv
我可以在那个容器中打开bash
:
$ docker run -i -t opencv /bin/bash
它安装了Debian:
# cat /etc/issue
Debian GNU/Linux 11 n l
它显示了opencv 4.5.1:
# apt install python3-opencv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-opencv is already the newest version (4.5.1+dfsg-5).
如果我尝试导入cv2,它没有找到:
# python3 -c "import cv2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
如果我问dpkg
,它会说应该有哪些文件:
# dpkg -L python3-opencv
/.
/usr
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/cv2.cpython-39-x86_64-linux-gnu.so
...
它们是:
# ls -l /usr/lib/python3/dist-packages/cv2.cpython-39-x86_64-linux-gnu.so
-rw-r--r-- 1 root root 6757472 Jun 16 2021 /usr/lib/python3/dist-packages/cv2.cpython-39-x86_64-linux-gnu.so
# which python3
/usr/local/bin/python3
所以。。缺少什么?我该如何使用看起来像已经安装好的opencv?有没有更简单的方法?
啊,看起来好像有两只蟒蛇。/usr/bin
中的一个有效。
# ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 9 Apr 5 2021 /usr/bin/python3 -> python3.9
# ls -l /usr/local/bin/python3
lrwxrwxrwx 1 root root 10 Apr 7 03:17 /usr/local/bin/python3 -> python3.10
# /usr/bin/python3 -c "import cv2"
#