我正在尝试运行cv2,当我尝试导入它时,我得到
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
建议的联机解决方案正在安装
apt install libgl1-mesa-glx
但是这已经安装好了,而且最新的version.Any帮助将会提前helpful.Thanks。
发布于 2021-08-05 12:21:39
即使上面的解决方案是有效的。但它们的包装尺寸相当大。libgl1
包提供了libGL.so.1
。因此,下面的代码就足够了。
apt-get update && apt-get install libgl1
发布于 2021-03-04 18:36:32
在我看来,这是一个更好的解决方案。Package python3-opencv
包含OpenCV的所有系统依赖项。
RUN apt-get update && apt-get install -y python3-opencv
RUN pip install opencv-python
发布于 2021-09-09 23:17:43
尝试安装opencv-python-headless
python依赖项而不是opencv-python
。这包括一个预编译的二进制轮子,没有外部依赖(除了numpy),并且旨在用于像Docker这样的无头环境。与使用python3-opencv
Debian包(及其所有依赖项)相比,这在我的docker镜像中节省了近700mb。
package documentation讨论了这一点以及相关的(更具扩展性的) opencv-contrib-python-headless
pypi包。
重现问题中的ImportError
的示例
# docker run -it python:3.9-slim bash -c "pip -q install opencv-python; python -c 'import cv2'"
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/cv2/__init__.py", line 5, in <module>
from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
# docker run -it python:3.9-slim bash -c "pip -q install opencv-python-headless; python -c 'import cv2'"
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
https://stackoverflow.com/questions/55313610
复制相似问题