2015-02-23 48 views
2

我已经安装numpy的和OpenCV采用的MacPorts按照these instructions,但是当我尝试import cvimport cv2我只是得到了段错误,我不知道为什么“进口CV2”时。Python的“分割故障:11”运行“进口品种”或

有什么建议吗?


$ python 
Python 2.7.6 (default, Sep 9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import cv 
Segmentation fault: 11 

$ python 
Python 2.7.6 (default, Sep 9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import cv2 
Segmentation fault: 11 

对不起有这么几个细节,但是这是一个新的电脑和我的MacPorts安装它只是为了这一点,这些都是我安装了唯一的东西与macports,所以我不知道为什么这不起作用。


编辑:现在我更困惑。

翻翻崩溃报告,我发现这一点:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes:  KERN_INVALID_ADDRESS at 0x0000000000000000 

所以,在黑暗中拍摄,我跑了Python作为超级用户:

$ sudo python 
Python 2.7.9 (default, Dec 13 2014, 15:13:49) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import cv 
>>> 

以超级用户身份,一切都显得运行良好。这怎么可能?

+1

尝试修复您的库的权限,因为我看到只有root可以访问它们。 – artemdevel 2015-02-23 09:29:56

回答

2

如果你仔细看看你的python命令的信息消息,你会看到不同之处。

从手推车的一个:

$ python 
Python 2.7.6 (default, Sep 9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import cv2 
Segmentation fault: 11 

从工作之一:

$ sudo python 
Python 2.7.9 (default, Dec 13 2014, 15:13:49) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import cv 
>>> 

你有你的机器上有两个不同版本的Python这或许可以解释你得到了行为。

+0

好的眼睛,我没有捕捉到......我如何使我的常规Python命令点超级用户Python指向的地方? – Ryan 2015-02-23 16:56:51

+0

嗯,我发现[this](http://sevas.github.io/2011/06/14/multiple-python-osx.html)和[this](http://superuser.com/questions/35256/我怎么能改变默认的python-version-on-snow-leopard)来讨论一些解决方案。也许你会发现他们有帮助。 – 2015-02-23 17:32:18

+2

非常感谢,'默认写入com.apple.versioner.python版本2.7.9'是我需要的命令。 – Ryan 2015-02-23 18:38:19

0

击中OSX 10.11这个问题,并通过在各种情况下这个问题的几种情况拖网后,我意识到这个问题发生由于大多如下独立的理由:

  1. 冲突的Python版本(一个以上的蟒蛇);解决方法 - 卸载其中一个,得到一个兼容opencv("Segmentation fault" during "import cv" on Mac OS
  2. opencv版本问题;解决方案 - 为您获得正确的版本Python opencv feature detector causes segmentation fault
  3. 问题与您的numpy版本;解决方案 - 卸载并重新安装numpy(OpenCV - cannot find module cv2

我试了所有3个,但3号解决了我的问题。

0

在代码的开头使用

cv2.ocl.setUseOpenCL(False) 

解决了这个问题对我来说。