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
ImportError: libSM.so.6: cannot open shared object file: No such file or directory
提问by Dmitry Rastorguev
When trying to import OpenCV, using import cv2
I 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-python
which 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 -headless
when 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_
回答by Utopia
I was facing similar issue with openCV on the python:3.7-slim
docker box. Following did the trick for me :
我在python:3.7-slim
docker 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 cv2
in the notebook.
现在刷新笔记本页面并通过import cv2
在笔记本中运行来检查它是否已安装。