问题:ImportError:libSM.so.6:无法打开共享库文件:没有这样的文件或目录

尝试导入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

不确定如何解决-尝试使用Google的新协作工具。笔记本在这里:https : //drive.google.com/file/d/0B7-sJqBiyjCcRmFkMzl6cy1iN0k/view?usp=sharing

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

/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 Colaboratory tool. Notebook is here: https://drive.google.com/file/d/0B7-sJqBiyjCcRmFkMzl6cy1iN0k/view?usp=sharing


回答 0

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

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

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
!apt-get install -y libxrender-dev

回答 1

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

sudo apt-get install libsm6 libxrender1 libfontconfig1

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

sudo python3 -m pip install opencv-contrib-python

终于完成了!

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

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 !


回答 2

对于CentOS,运行以下命令: sudo yum install libXext libSM libXrender

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


回答 3

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

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

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

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

回答 4

可能是您的问题 python-opencv版本。最好将您的版本降级到3.3.0.9,其中不包含任何GUI依赖项。在GitHub的此处找到了相同的问题的答案链接。

May be the problem is with your python-opencv version. 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.


回答 5

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

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

请查看是否有帮助!

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

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

Please see if this helps !


回答 6

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

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

 sudo apt-get install libsm6 libxrender1 libfontconfig1

安装完毕后,打开Jupyter笔记本并运行以下命令:

!pip install opencv-contrib-python

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

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

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:

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

 sudo apt-get install libsm6 libxrender1 libfontconfig1

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

!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.

Now refresh the notebook page and check whether it’s installed or not by running import cv2 in the notebook.


回答 7

我遇到了同样的问题docker这些步骤对我有用:

apt update

然后:

apt install libsm6 libxext6 libxrender-dev

I had the same problem in docker and these steps worked for me:

apt update

then:

apt install libsm6 libxext6 libxrender-dev

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。