I cannot use opencv2 and received ImportError: libgl.so.1 cannot open shared object file no such file or directory
I cannot use opencv2 and received ImportError: libgl.so.1 cannot open shared object file no such file or directory
**env:**ubuntu16.04 anaconda3 python3.7.8 cuda10.0 gcc5.5
命令:
conda activate myenv
python
import cv2
错误:
追溯(最近一次通话):
文件“”,第 1 行,位于
文件“/home/.conda/envs/myenv/lib/python3.7/site-packages/cv2/__init__.py”,第 5 行,位于
从 .cv2 导入 *
导入错误:libGL.so.1:无法打开共享对象文件:没有这样的文件或目录
我试过了:
RUN apt install libgl1-mesa-glx -y
RUN apt-get install 'ffmpeg'\
'libsm6'\
'libxext6' -y
但这已经安装并且是最新版本(libgl1-mesa-glx18.0.5-0ubuntu0~16.04.1)。
然后我试了:
sudo apt-get install --reinstall libgl1-mesa-glx
没用。
最后,我尝试删除包:
sudo apt-get --purge remove libgl1-mesa-glx
出现另一个错误:
Reading package list... Done
Analyzing the dependency tree of the package
Reading status information... Done
Some packages cannot be installed. If you are using an unstable distribution, this may be
Because the system cannot reach the state you requested. There may be some software you need in this version
The packages have not been created yet or they have been moved out of the Incoming directory.
The following information may be helpful in solving the problem:
The following packages have unmet dependencies:
libqt5multimedia5-plugins: Dependency: libqgsttools-p1 (>= 5.5.1) but it will not be installed
E: Error, pkgProblemResolver::Resolve failed. This may be due to a software package being required to maintain the status quo.
任何帮助都会提前helpful.Thanks。
conda 列表:
# packages in environment at /home/lwy/.conda/envs/mmdet1:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
_openmp_mutex 4.5 1_gnu https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
addict 2.3.0 <pip>
albumentations 0.5.1 <pip>
appdirs 1.4.4 <pip>
asynctest 0.13.0 <pip>
attrs 20.2.0 <pip>
ca-certificates 2020.6.20 hecda079_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
certifi 2020.6.20 py37he5f6b98_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
chardet 3.0.4 <pip>
cityscapesScripts 2.1.7 <pip>
codecov 2.1.10 <pip>
coloredlogs 14.0 <pip>
coverage 5.3 <pip>
cycler 0.10.0 <pip>
Cython 0.29.21 <pip>
decorator 4.4.2 <pip>
flake8 3.8.4 <pip>
future 0.18.2 <pip>
humanfriendly 8.2 <pip>
idna 2.10 <pip>
imagecorruptions 1.1.0 <pip>
imageio 2.9.0 <pip>
imgaug 0.4.0 <pip>
importlib-metadata 2.0.0 <pip>
iniconfig 1.1.1 <pip>
isort 5.6.4 <pip>
kiwisolver 1.3.1 <pip>
kwarray 0.5.10 <pip>
ld_impl_linux-64 2.35 h769bd43_9 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libffi 3.2.1 1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
libgcc-ng 9.3.0 h5dbcf3e_17 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libgomp 9.3.0 h5dbcf3e_17 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng 9.3.0 h2ae2ef3_17 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
matplotlib 3.3.2 <pip>
mccabe 0.6.1 <pip>
mmcv 1.1.6 <pip>
mmdet 1.2.0+unknown <pip>
ncurses 6.2 he1b5a44_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
networkx 2.5 <pip>
numpy 1.19.4 <pip>
opencv-python 4.4.0.46 <pip>
openssl 1.1.1h h516909a_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ordered-set 4.0.2 <pip>
packaging 20.4 <pip>
Pillow 6.2.2 <pip>
pip 20.2.4 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pluggy 0.13.1 <pip>
py 1.9.0 <pip>
pycocotools 2.0 <pip>
pycodestyle 2.6.0 <pip>
pyflakes 2.2.0 <pip>
pyparsing 2.4.7 <pip>
pyquaternion 0.9.9 <pip>
pytest 6.1.2 <pip>
pytest-cov 2.10.1 <pip>
pytest-runner 5.2 <pip>
python 3.7.8 h6f2ec95_1_cpython https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python-dateutil 2.8.1 <pip>
python_abi 3.7 1_cp37m https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
PyWavelets 1.1.1 <pip>
PyYAML 5.3.1 <pip>
readline 8.0 he28a2e2_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
requests 2.24.0 <pip>
scikit-image 0.17.2 <pip>
scipy 1.5.3 <pip>
setuptools 49.6.0 py37he5f6b98_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
Shapely 1.7.1 <pip>
six 1.15.0 <pip>
sqlite 3.33.0 h4cf870e_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
tifffile 2020.10.1 <pip>
tk 8.6.10 hed695b0_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
toml 0.10.2 <pip>
torch 1.5.0+cu92 <pip>
torchvision 0.6.0+cu92 <pip>
tqdm 4.51.0 <pip>
typing 3.7.4.3 <pip>
ubelt 0.9.3 <pip>
urllib3 1.25.11 <pip>
wheel 0.35.1 pyh9f0ad1d_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
xdoctest 0.15.0 <pip>
xz 5.2.5 h516909a_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
yapf 0.30.0 <pip>
zipp 3.4.0 <pip>
zlib 1.2.11 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
我已经解决了这个问题!
首先,找到文件:
find /usr -name libgl*
我找到了 /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1
然后,我创建了一个软 link:
ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so.1
最后,我验证了它是有效的:
python
import cv2
通常这些包是作为系统包安装的,而不仅仅是 Python 包。因此,很多时候即使成功安装了 opencv
、cmake
、dlib
等软件包,它们也无法正常工作。
最好的方法是安装它们。
sudo apt-get install python3-opencv
根据官方 Opencv Docs.
,这是在 Ubuntu 上成功安装 opencv 的首选方法
**env:**ubuntu16.04 anaconda3 python3.7.8 cuda10.0 gcc5.5
命令:
conda activate myenv
python
import cv2
错误: 追溯(最近一次通话): 文件“”,第 1 行,位于 文件“/home/.conda/envs/myenv/lib/python3.7/site-packages/cv2/__init__.py”,第 5 行,位于 从 .cv2 导入 * 导入错误:libGL.so.1:无法打开共享对象文件:没有这样的文件或目录
我试过了:
RUN apt install libgl1-mesa-glx -y
RUN apt-get install 'ffmpeg'\
'libsm6'\
'libxext6' -y
但这已经安装并且是最新版本(libgl1-mesa-glx18.0.5-0ubuntu0~16.04.1)。 然后我试了:
sudo apt-get install --reinstall libgl1-mesa-glx
没用。 最后,我尝试删除包:
sudo apt-get --purge remove libgl1-mesa-glx
出现另一个错误:
Reading package list... Done
Analyzing the dependency tree of the package
Reading status information... Done
Some packages cannot be installed. If you are using an unstable distribution, this may be
Because the system cannot reach the state you requested. There may be some software you need in this version
The packages have not been created yet or they have been moved out of the Incoming directory.
The following information may be helpful in solving the problem:
The following packages have unmet dependencies:
libqt5multimedia5-plugins: Dependency: libqgsttools-p1 (>= 5.5.1) but it will not be installed
E: Error, pkgProblemResolver::Resolve failed. This may be due to a software package being required to maintain the status quo.
任何帮助都会提前helpful.Thanks。
conda 列表:
# packages in environment at /home/lwy/.conda/envs/mmdet1:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
_openmp_mutex 4.5 1_gnu https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
addict 2.3.0 <pip>
albumentations 0.5.1 <pip>
appdirs 1.4.4 <pip>
asynctest 0.13.0 <pip>
attrs 20.2.0 <pip>
ca-certificates 2020.6.20 hecda079_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
certifi 2020.6.20 py37he5f6b98_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
chardet 3.0.4 <pip>
cityscapesScripts 2.1.7 <pip>
codecov 2.1.10 <pip>
coloredlogs 14.0 <pip>
coverage 5.3 <pip>
cycler 0.10.0 <pip>
Cython 0.29.21 <pip>
decorator 4.4.2 <pip>
flake8 3.8.4 <pip>
future 0.18.2 <pip>
humanfriendly 8.2 <pip>
idna 2.10 <pip>
imagecorruptions 1.1.0 <pip>
imageio 2.9.0 <pip>
imgaug 0.4.0 <pip>
importlib-metadata 2.0.0 <pip>
iniconfig 1.1.1 <pip>
isort 5.6.4 <pip>
kiwisolver 1.3.1 <pip>
kwarray 0.5.10 <pip>
ld_impl_linux-64 2.35 h769bd43_9 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libffi 3.2.1 1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
libgcc-ng 9.3.0 h5dbcf3e_17 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libgomp 9.3.0 h5dbcf3e_17 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng 9.3.0 h2ae2ef3_17 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
matplotlib 3.3.2 <pip>
mccabe 0.6.1 <pip>
mmcv 1.1.6 <pip>
mmdet 1.2.0+unknown <pip>
ncurses 6.2 he1b5a44_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
networkx 2.5 <pip>
numpy 1.19.4 <pip>
opencv-python 4.4.0.46 <pip>
openssl 1.1.1h h516909a_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ordered-set 4.0.2 <pip>
packaging 20.4 <pip>
Pillow 6.2.2 <pip>
pip 20.2.4 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pluggy 0.13.1 <pip>
py 1.9.0 <pip>
pycocotools 2.0 <pip>
pycodestyle 2.6.0 <pip>
pyflakes 2.2.0 <pip>
pyparsing 2.4.7 <pip>
pyquaternion 0.9.9 <pip>
pytest 6.1.2 <pip>
pytest-cov 2.10.1 <pip>
pytest-runner 5.2 <pip>
python 3.7.8 h6f2ec95_1_cpython https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python-dateutil 2.8.1 <pip>
python_abi 3.7 1_cp37m https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
PyWavelets 1.1.1 <pip>
PyYAML 5.3.1 <pip>
readline 8.0 he28a2e2_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
requests 2.24.0 <pip>
scikit-image 0.17.2 <pip>
scipy 1.5.3 <pip>
setuptools 49.6.0 py37he5f6b98_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
Shapely 1.7.1 <pip>
six 1.15.0 <pip>
sqlite 3.33.0 h4cf870e_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
tifffile 2020.10.1 <pip>
tk 8.6.10 hed695b0_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
toml 0.10.2 <pip>
torch 1.5.0+cu92 <pip>
torchvision 0.6.0+cu92 <pip>
tqdm 4.51.0 <pip>
typing 3.7.4.3 <pip>
ubelt 0.9.3 <pip>
urllib3 1.25.11 <pip>
wheel 0.35.1 pyh9f0ad1d_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
xdoctest 0.15.0 <pip>
xz 5.2.5 h516909a_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
yapf 0.30.0 <pip>
zipp 3.4.0 <pip>
zlib 1.2.11 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
我已经解决了这个问题! 首先,找到文件:
find /usr -name libgl*
我找到了 /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 然后,我创建了一个软 link:
ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so.1
最后,我验证了它是有效的:
python
import cv2
通常这些包是作为系统包安装的,而不仅仅是 Python 包。因此,很多时候即使成功安装了 opencv
、cmake
、dlib
等软件包,它们也无法正常工作。
最好的方法是安装它们。
sudo apt-get install python3-opencv
根据官方 Opencv Docs.
,这是在 Ubuntu 上成功安装 opencv 的首选方法