This repository has been archived by the owner. It is now read-only.

Homebrew'd OpenCV Python module segfaults on import #16016

Closed
fish2000 opened this Issue Nov 13, 2012 · 14 comments

Comments

@fish2000
Contributor

fish2000 commented Nov 13, 2012

This gist has both the verbose compilation output and the Console.app crash log in full:

https://gist.github.com/4064775

At the end of the first file is the meat of the issue:

[ ... SNIP ...]
ln -s ../Cellar/opencv/2.4.2/lib/libopencv_calib3d.2.4.dylib libopencv_calib3d.2.4.dylib
ln -s ../Cellar/opencv/2.4.2/lib/libopencv_calib3d.2.4.2.dylib libopencv_calib3d.2.4.2.dylib
ln -s ../../Cellar/opencv/2.4.2 opencv
ln -s ../Cellar/opencv/2.4.2 opencv
==> Summary
/usr/local/Cellar/opencv/2.4.2: 184 files, 48M, built in 5.5 minutes
ASIO-OTUS:ost2[ost6]$ python -c 'import cv'
Segmentation fault: 11
ASIO-OTUS:ost2[ost6]$ python -c 'import cv2'
Segmentation fault: 11

I have tried building it with and without the --with-tbb and --with-qt options and the results are the same in all of these cases: segfault number eleven.

@2bits

This comment has been minimized.

Show comment
Hide comment
@2bits

2bits Nov 13, 2012

Contributor

The opencv compilation log you posted said this:

-- Found PythonInterp: /usr/local/bin/python2 (found suitable version "2.7.3", minimum required is "2.0") 
-- Could NOT find PythonLibs: Found unsuitable version "2.7.1", but required is exact version "2.7.3" (found /System/Library/Frameworks/Python.framework/Versions/2.7/Python)

among other things, which indicates that there is small problem that I thought was solved months ago, but things change. Let me try it here with Homebrew Python on 10.8.2 and see what adjustment needs to be made.

Contributor

2bits commented Nov 13, 2012

The opencv compilation log you posted said this:

-- Found PythonInterp: /usr/local/bin/python2 (found suitable version "2.7.3", minimum required is "2.0") 
-- Could NOT find PythonLibs: Found unsuitable version "2.7.1", but required is exact version "2.7.3" (found /System/Library/Frameworks/Python.framework/Versions/2.7/Python)

among other things, which indicates that there is small problem that I thought was solved months ago, but things change. Let me try it here with Homebrew Python on 10.8.2 and see what adjustment needs to be made.

@2bits

This comment has been minimized.

Show comment
Hide comment
@2bits

2bits Nov 13, 2012

Contributor

It works for me. You probably just need to reinstall Homebrew Python and try again. If brew install -vd --tbb opencv still fails, choose for it to shell out when it errors, and tell use what you get for

which python-config
ls -ld /usr/local/opt/python
Contributor

2bits commented Nov 13, 2012

It works for me. You probably just need to reinstall Homebrew Python and try again. If brew install -vd --tbb opencv still fails, choose for it to shell out when it errors, and tell use what you get for

which python-config
ls -ld /usr/local/opt/python
@samueljohn

This comment has been minimized.

Show comment
Hide comment
@samueljohn

samueljohn Nov 14, 2012

Contributor

Right, Segmentation fault: 11 is in 95% due to a different python version used for building the software vs. the python you use to import the stuff. This happens for python packages with c-extensions, which are built with different options (e.g. Apple's python is still not a pure 64bit).

You should perhaps brew rm python, then brew install python and then attempt to brew install -vd --tbb opencv. Make sure to launch the brewed python when importing.

It should also work to avoid homebrewed python and only use Apple's (older) python. But you can't mix.

Contributor

samueljohn commented Nov 14, 2012

Right, Segmentation fault: 11 is in 95% due to a different python version used for building the software vs. the python you use to import the stuff. This happens for python packages with c-extensions, which are built with different options (e.g. Apple's python is still not a pure 64bit).

You should perhaps brew rm python, then brew install python and then attempt to brew install -vd --tbb opencv. Make sure to launch the brewed python when importing.

It should also work to avoid homebrewed python and only use Apple's (older) python. But you can't mix.

@samueljohn

This comment has been minimized.

Show comment
Hide comment
@samueljohn

samueljohn Dec 5, 2012

Contributor

@fish2000 what's the status?

Contributor

samueljohn commented Dec 5, 2012

@fish2000 what's the status?

@cooncesean

This comment has been minimized.

Show comment
Hide comment
@cooncesean

cooncesean Dec 6, 2012

I was struggling with this exact same issue and following @samueljohn's advice solved my issue.

A gotchas for other python developers to keep an eye on:

  • PATH: Assert that your path (before you brew install opencv) has /usr/local/bin: prepending everything else.
  • PYTHONPATH: Assert that your pythonpath looks something like: PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"

With these settings in place, opencv should get built against the appropriate architecture and its python bindings should be installed somewhere on your path.

I can't believe I finally got this working on my Mac - thank you.

cooncesean commented Dec 6, 2012

I was struggling with this exact same issue and following @samueljohn's advice solved my issue.

A gotchas for other python developers to keep an eye on:

  • PATH: Assert that your path (before you brew install opencv) has /usr/local/bin: prepending everything else.
  • PYTHONPATH: Assert that your pythonpath looks something like: PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"

With these settings in place, opencv should get built against the appropriate architecture and its python bindings should be installed somewhere on your path.

I can't believe I finally got this working on my Mac - thank you.

@samueljohn

This comment has been minimized.

Show comment
Hide comment
@samueljohn

samueljohn Dec 6, 2012

Contributor

I'll put that note in the wiki, I guess.
@fish2000 is it working for you, too?

Contributor

samueljohn commented Dec 6, 2012

I'll put that note in the wiki, I guess.
@fish2000 is it working for you, too?

@samueljohn

This comment has been minimized.

Show comment
Hide comment
Contributor

samueljohn commented Dec 6, 2012

@jacknagel

This comment has been minimized.

Show comment
Hide comment
@jacknagel

jacknagel Dec 22, 2012

Contributor

Closing due to (a) lack of response and (b) assumption that the solution outlined above will solve the problem.

Contributor

jacknagel commented Dec 22, 2012

Closing due to (a) lack of response and (b) assumption that the solution outlined above will solve the problem.

@ssbanerje

This comment has been minimized.

Show comment
Hide comment
@ssbanerje

ssbanerje Apr 16, 2013

Couldn't you put in a check to recompile all the software that builds c-python extensions?

ssbanerje commented Apr 16, 2013

Couldn't you put in a check to recompile all the software that builds c-python extensions?

@selectersky

This comment has been minimized.

Show comment
Hide comment
@selectersky

selectersky May 13, 2014

first:use brew install python:
$brew install python
and installation path is:/usr/local/Cellar/python/2.7.6_1
modify ~/.bash_profile,set new python bin file

type below command:
$brew remove opencv
$brew install opencv
$cd /usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
$ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
$ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so

my succeed!

selectersky commented May 13, 2014

first:use brew install python:
$brew install python
and installation path is:/usr/local/Cellar/python/2.7.6_1
modify ~/.bash_profile,set new python bin file

type below command:
$brew remove opencv
$brew install opencv
$cd /usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
$ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
$ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so

my succeed!

@benedictes

This comment has been minimized.

Show comment
Hide comment
@benedictes

benedictes Jun 16, 2014

the last two lines (symbolic links) in selectersky's recipe finally made it work. Could someone please explain why this is needed?

benedictes commented Jun 16, 2014

the last two lines (symbolic links) in selectersky's recipe finally made it work. Could someone please explain why this is needed?

@Spechal

This comment has been minimized.

Show comment
Hide comment
@Spechal

Spechal Aug 31, 2014

I had to do the same things as @selectersky ... finally opencv ... many battles, many loses, one battle, much win, war over

Spechal commented Aug 31, 2014

I had to do the same things as @selectersky ... finally opencv ... many battles, many loses, one battle, much win, war over

@xuzonghan

This comment has been minimized.

Show comment
Hide comment
@xuzonghan

xuzonghan Nov 19, 2014

Hi, I encountered the same problem
This is my bash_profile

export OCI_HOME=/Applications/instantclient_11_2;
export OCI_LIB_DIR=$OCI_HOME;
export OCI_INCLUDE_DIR=$OCI_HOME/sdk/include;
export OCI_VERSION=11;
export DYLD_LIBRARY_PATH=$OCI_LIB_DIR;
export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

Anything wrong here?

PS:

hntvlan569:testDrone_video xuxu$ which python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
hntvlan569:testDrone_video xuxu$ ls -ld /usr/local/opt/python
lrwxr-xr-x 1 xuxu wheel 24 Nov 18 22:45 /usr/local/opt/python -> ../Cellar/python/2.7.8_2

xuzonghan commented Nov 19, 2014

Hi, I encountered the same problem
This is my bash_profile

export OCI_HOME=/Applications/instantclient_11_2;
export OCI_LIB_DIR=$OCI_HOME;
export OCI_INCLUDE_DIR=$OCI_HOME/sdk/include;
export OCI_VERSION=11;
export DYLD_LIBRARY_PATH=$OCI_LIB_DIR;
export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

Anything wrong here?

PS:

hntvlan569:testDrone_video xuxu$ which python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
hntvlan569:testDrone_video xuxu$ ls -ld /usr/local/opt/python
lrwxr-xr-x 1 xuxu wheel 24 Nov 18 22:45 /usr/local/opt/python -> ../Cellar/python/2.7.8_2

@TLiu2014

This comment has been minimized.

Show comment
Hide comment
@TLiu2014

TLiu2014 May 19, 2015

I followed comments from @samueljohn on Nov 14, 2012 and removed the python 2.7.8 installed by homebrew. Now, there is only one python, version 2.7.9, on my mac. I could import cv and cv2 freely.

TLiu2014 commented May 19, 2015

I followed comments from @samueljohn on Nov 14, 2012 and removed the python 2.7.8 installed by homebrew. Now, there is only one python, version 2.7.9, on my mac. I could import cv and cv2 freely.

@Homebrew Homebrew locked and limited conversation to collaborators May 19, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.