Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Homebrew'd OpenCV Python module segfaults on import #16016

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

Homebrew'd OpenCV Python module segfaults on import #16016

fish2000 opened this issue Nov 13, 2012 · 14 comments
Labels

Comments

@fish2000
Copy link
Contributor

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
Copy link
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
Copy link
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
Copy link
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.

@samueljohn
Copy link
Contributor

@fish2000 what's the status?

@cooncesean
Copy link

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
Copy link
Contributor

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

@samueljohn
Copy link
Contributor

@jacknagel
Copy link
Contributor

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

@ssbanerje
Copy link

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

@selectersky
Copy link

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!

@benedicteslee
Copy link

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

@Spechal
Copy link

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
Copy link

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
Copy link

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.
Labels
Projects
None yet
Development

No branches or pull requests