我无法使用 opencv2 并收到 ImportError: libgl.so.1 无法打开共享对象文件,没有这样的文件或目录

nob*_*bug 6 python opencv importerror ubuntu-16.04 anaconda3

**环境:**ubuntu16.04 anaconda3 python3.7.8 cuda10.0 gcc5.5

\n

命令:

\n
conda activate myenv\npython\nimport cv2\n
Run Code Online (Sandbox Code Playgroud)\n

错误: \n回溯(最近一次调用):\n文件“”,第 1 行,在\n文件“/home/.conda/envs/myenv/lib/python3.7/site-packages/cv2/__init__.py”中,第 5 行,在 \nfrom .cv2 import *\nImportError: libGL.so.1: 无法打开共享对象文件: 没有这样的文件或目录

\n

我试过:

\n
RUN apt install libgl1-mesa-glx -y\n    RUN apt-get install 'ffmpeg'\\\n        'libsm6'\\\n        'libxext6'  -y\n
Run Code Online (Sandbox Code Playgroud)\n

但这已经安装并且是最新版本(libgl1-mesa-glx18.0.5-0ubuntu0~16.04.1)。\n然后我尝试了:

\n
sudo apt-get install --reinstall libgl1-mesa-glx\n
Run Code Online (Sandbox Code Playgroud)\n

它不起作用。\n最后,我尝试删除该包:

\n
sudo apt-get --purge remove libgl1-mesa-glx\n
Run Code Online (Sandbox Code Playgroud)\n

发生另一个错误\xef\xbc\x9a

\n
Reading package list... Done\nAnalyzing the dependency tree of the package\nReading status information... Done\nSome packages cannot be installed. If you are using an unstable distribution, this may be\nBecause the system cannot reach the state you requested. There may be some software you need in this version\nThe packages have not been created yet or they have been moved out of the Incoming directory.\nThe following information may be helpful in solving the problem:\n\nThe following packages have unmet dependencies:\n libqt5multimedia5-plugins: Dependency: libqgsttools-p1 (>= 5.5.1) but it will not be installed\nE: Error, pkgProblemResolver::Resolve failed. This may be due to a software package being required to maintain the status quo.\n
Run Code Online (Sandbox Code Playgroud)\n

任何帮助都会非常有帮助。提前致谢。

\n

康达清单:

\n
# packages in environment at /home/lwy/.conda/envs/mmdet1:\n#\n# Name                    Version                   Build  Channel\n_libgcc_mutex             0.1                 conda_forge    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\n_openmp_mutex             4.5                       1_gnu    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\naddict                    2.3.0                     <pip>\nalbumentations            0.5.1                     <pip>\nappdirs                   1.4.4                     <pip>\nasynctest                 0.13.0                    <pip>\nattrs                     20.2.0                    <pip>\nca-certificates           2020.6.20            hecda079_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\ncertifi                   2020.6.20        py37he5f6b98_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nchardet                   3.0.4                     <pip>\ncityscapesScripts         2.1.7                     <pip>\ncodecov                   2.1.10                    <pip>\ncoloredlogs               14.0                      <pip>\ncoverage                  5.3                       <pip>\ncycler                    0.10.0                    <pip>\nCython                    0.29.21                   <pip>\ndecorator                 4.4.2                     <pip>\nflake8                    3.8.4                     <pip>\nfuture                    0.18.2                    <pip>\nhumanfriendly             8.2                       <pip>\nidna                      2.10                      <pip>\nimagecorruptions          1.1.0                     <pip>\nimageio                   2.9.0                     <pip>\nimgaug                    0.4.0                     <pip>\nimportlib-metadata        2.0.0                     <pip>\niniconfig                 1.1.1                     <pip>\nisort                     5.6.4                     <pip>\nkiwisolver                1.3.1                     <pip>\nkwarray                   0.5.10                    <pip>\nld_impl_linux-64          2.35                 h769bd43_9    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nlibffi                    3.2.1                         1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free\nlibgcc-ng                 9.3.0               h5dbcf3e_17    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nlibgomp                   9.3.0               h5dbcf3e_17    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nlibstdcxx-ng              9.3.0               h2ae2ef3_17    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nmatplotlib                3.3.2                     <pip>\nmccabe                    0.6.1                     <pip>\nmmcv                      1.1.6                     <pip>\nmmdet                     1.2.0+unknown             <pip>\nncurses                   6.2                  he1b5a44_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nnetworkx                  2.5                       <pip>\nnumpy                     1.19.4                    <pip>\nopencv-python             4.4.0.46                  <pip>\nopenssl                   1.1.1h               h516909a_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nordered-set               4.0.2                     <pip>\npackaging                 20.4                      <pip>\nPillow                    6.2.2                     <pip>\npip                       20.2.4                     py_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\npluggy                    0.13.1                    <pip>\npy                        1.9.0                     <pip>\npycocotools               2.0                       <pip>\npycodestyle               2.6.0                     <pip>\npyflakes                  2.2.0                     <pip>\npyparsing                 2.4.7                     <pip>\npyquaternion              0.9.9                     <pip>\npytest                    6.1.2                     <pip>\npytest-cov                2.10.1                    <pip>\npytest-runner             5.2                       <pip>\npython                    3.7.8           h6f2ec95_1_cpython    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\npython-dateutil           2.8.1                     <pip>\npython_abi                3.7                     1_cp37m    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nPyWavelets                1.1.1                     <pip>\nPyYAML                    5.3.1                     <pip>\nreadline                  8.0                  he28a2e2_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nrequests                  2.24.0                    <pip>\nscikit-image              0.17.2                    <pip>\nscipy                     1.5.3                     <pip>\nsetuptools                49.6.0           py37he5f6b98_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nShapely                   1.7.1                     <pip>\nsix                       1.15.0                    <pip>\nsqlite                    3.33.0               h4cf870e_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\ntifffile                  2020.10.1                 <pip>\ntk                        8.6.10               hed695b0_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\ntoml                      0.10.2                    <pip>\ntorch                     1.5.0+cu92                <pip>\ntorchvision               0.6.0+cu92                <pip>\ntqdm                      4.51.0                    <pip>\ntyping                    3.7.4.3                   <pip>\nubelt                     0.9.3                     <pip>\nurllib3                   1.25.11                   <pip>\nwheel                     0.35.1             pyh9f0ad1d_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nxdoctest                  0.15.0                    <pip>\nxz                        5.2.5                h516909a_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge\nyapf                      0.30.0                    <pip>\nzipp                      3.4.0                     <pip>\nzlib                      1.2.11                        0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free\n
Run Code Online (Sandbox Code Playgroud)\n

小智 8

通常这些包是作为系统包安装的,而不仅仅是 Python 包。因此,很多时候,即使成功安装了 、 等软件包opencv,它们cmakedlib不起作用。

最好的方法是安装它们并使用。

sudo apt-get install python3-opencv
Run Code Online (Sandbox Code Playgroud)

根据Opencv 官方文档,这是在 Ubuntu 上成功安装 opencv 的首选方法。


Geo*_*een 5

我能够通过以下方式解决问题

apt-get install libgl1 
Run Code Online (Sandbox Code Playgroud)


nob*_*bug 2

我已经解决了这个问题!首先,找到该文件:

find /usr -name libGL.so.1
Run Code Online (Sandbox Code Playgroud)

我发现/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1。然后,我创建了一个软链接:

ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so.1
Run Code Online (Sandbox Code Playgroud)

最后,我验证了它的有效性:

# python
import cv2
Run Code Online (Sandbox Code Playgroud)