Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python "Segmentation fault: 11" when running "import cv" or "import cv2"

I have installed numpy and opencv using macports as per these instructions, but when I try import cv or import cv2 I just get the segfault and I have no idea why.

Any suggestions?


$ 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

Sorry there are so few details, but this is a new computer and I installed macports on it just for this, and these are the only things I've installed with macports, so I have no idea why this isn't working.


Edit: Now I'm More Confused.

Looking through the crash report I found this:

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

So, as a shot in the dark, I ran python as super user:

$ 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
>>>

As super user, everything appears to run fine. How is this possible?

like image 574
Ryan Avatar asked Dec 04 '25 14:12

Ryan


1 Answers

If you look closely to the info message of your python command, you will see the difference.

From the buggy one:

$ 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

From the working one:

$ 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
>>>

You have two different versions of Python on your machine which might explain the behaviors you got.

like image 185
Ha Dang Avatar answered Dec 07 '25 03:12

Ha Dang