Python 导入错误:libSM.so.6:无法打开共享对象文件:没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47113029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:00:44  来源:igfitidea点击:

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

pythonopencvpython-importimporterrorpython-module

提问by Dmitry Rastorguev

When trying to import OpenCV, using import cv2I get the following error:

尝试导入 OpenCV 时,使用时import cv2出现以下错误:

/usr/local/lib/python2.7/dist-packages/cv2/__init__.py in <module>()
      7 
      8 # make IDE's (PyCharm) autocompletion happy
----> 9 from .cv2 import *
     10 
     11 # wildcard import above does not import "private" variables like __version__

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

Not sure how to fix this - trying to play around with Google's new Colaboratorytool. Notebook is here: https://drive.google.com/file/d/0B7-sJqBiyjCcRmFkMzl6cy1iN0k/view?usp=sharing

不知道如何解决这个问题 - 尝试使用 Google 的新Colaboratory工具。笔记本在这里:https: //drive.google.com/file/d/0B7-sJqBiyjCcRmFkMzl6cy1iN0k/view?usp=sharing

回答by Dmitry Rastorguev

This fixed the problem by having it as the first two lines of the script:

这通过将其作为脚本的前两行来解决问题:

!pip install opencv-python
!apt update && apt install -y libsm6 libxext6

回答by Soufiane Chami

You need to add sudo . I did the following to get it installed :

您需要添加 sudo 。我做了以下操作来安装它:

sudo apt-get install libsm6 libxrender1 libfontconfig1

and then did that (optional! maybe you won't need it)

然后这样做(可选!也许你不需要它)

sudo python3 -m pip install opencv-contrib-python

FINALLY got it done !

终于搞定了!

回答by Caesar

For CentOS, run this: sudo yum install libXext libSM libXrender

对于 CentOS,请运行: sudo yum install libXext libSM libXrender

回答by Nathan

There is now a headless version of opencv-pythonwhich removes the graphical dependencies (like libSM). You can see the normal / headless version on the releases page(and the GitHub issueleading to this); just add -headlesswhen installing, e.g.,

现在有一个无头版本,opencv-python它删除了图形依赖项(如 libSM)。您可以在发布页面上看到普通/无头版本(以及导致此问题GitHub 问题);只需-headless在安装时添加,例如,

pip install opencv-python-headless
# also contrib, if needed
pip install opencv-contrib-python-headless

回答by de_billa_

May be the problem is with your python-opencvversion. It's better to downgrade your version to 3.3.0.9 which does not include any GUI dependencies. Same question was found on GitHub here the link to the answer.

可能是你的python-opencv版本有问题。最好将您的版本降级到不包含任何 GUI 依赖项的 3.3.0.9。同样的问题在 GitHub 上找到了答案的链接。

回答by Utopia

I was facing similar issue with openCV on the python:3.7-slimdocker box. Following did the trick for me :

我在python:3.7-slimdocker box上遇到了与 openCV 类似的问题。以下对我有用:

apt-get install build-essential libglib2.0-0 libsm6 libxext6 libxrender-dev

Please see if this helps !

请看看这是否有帮助!

回答by Yogesh

I was not able to install cv2 on Anaconda-Jupyter notebook running on Ubuntu on Google Cloud Platform. But I found a way to do it as follows:

我无法在 Google Cloud Platform 上的 Ubuntu 上运行的 Anaconda-Jupyter 笔记本上安装 cv2。但我找到了一种方法,如下所示:

Run the following command from the ssh terminal and follow the instruction:

从 ssh 终端运行以下命令并按照说明进行操作:

 sudo apt-get install libsm6 libxrender1 libfontconfig1

Once its installed Open the Jupyter notebook and run following command:

安装后打开 Jupyter notebook 并运行以下命令:

!pip install opencv-contrib-python

Note: I tried to run this command: "sudo python3 -m pip install opencv-contrib-python"but it was showing an error. But above command worked for me.

注意:我尝试运行此命令:“sudo python3 -m pip install opencv-contrib-python”但它显示错误。但上面的命令对我有用。

Now refresh the notebook page and check whether it's installed or not by running import cv2in the notebook.

现在刷新笔记本页面并通过import cv2在笔记本中运行来检查它是否已安装。