Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Segmentation fault and crashing when trying to import opencv

I have mac os x 10.9. I downloaded opencv-python using homebrew and I have both the python 2.7 and python 3.4 versions off of the main python site, downloaded the usual way with macs. I need to use opencv, but they do not have a download package for macs so I used homebrew:

brew tap homebrew/science
brew install opencv

When I type python into the terminal, and then type import cv, I get a segmentation error and python quits unexpectedly. The same thing happens in IDLE. For python 3.4, I get a no module error. Here it is:

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/aurora_alvarez-buylla/cv.py", line 1, in <module>
    from cv2.cv import *
ImportError: No module named 'cv2'

Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Segmentation fault: 11

and then it quits unexpectedly. Does anyone know what is going on? Frankly I have spent way too much time on this opencv issue and am finding it very frustrating. Thank you!

like image 443
user1558576 Avatar asked Jun 06 '14 14:06

user1558576


1 Answers

Chris Muktar pointed in this thread that the problem is caused by the conflict between the system Python and brewed Python. Following that idea, I resolved this issue by removing the system python and re-installing opencv:

$ cd /usr/bin
$ sudo mv python python.bak
$ brew uninstall opencv
$ brew install opencv    
like image 132
Penghe Geng Avatar answered Oct 16 '22 18:10

Penghe Geng