2015-02-23 51 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) 

解決了這個問題對我來說。