1

I'm attempting to install OpenCV for use with Python. The first install went great; however, I was missing the cv2.so file. I then added -D BUILD_NEW_PYTHON_SUPPORT=ON in hopes that it would create the cv2.so file for me.

Full command:

cmake -D CMAKE_INSTALL_PREFIX=${target} -D CMAKE_FIND_ROOT_PATH=${target} -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_SHARED_LIBS=OFF -D CMAKE_SHARED_LINKER_FLAGS="-fPIC" ..

Around 92%, OpenCV fails with the following:

Scanning dependencies of target opencv_python
    [ 92%] Building CXX object modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o
    Linking CXX shared library ../../lib/cv2.so
/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/cv2.so] Error 1
make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2
make: *** [all] Error 2
ERROR: Build failed, exited 2

Running the default version of Python 2.7.6 that Heroku installs. I've come across a few posts that suggest the need for python-dev, but it looks like the dev headers are already there (Screenshot).

I'm using a custom buildpack if that's of any help.

Nick Parsons
  • 8,377
  • 13
  • 48
  • 70
  • Related problems with possibly working solutions: ["Heroku and OpenCV with Python"](http://stackoverflow.com/q/19879663/2419207), ["OpenCV Python Linker Error"](http://stackoverflow.com/q/20622583/2419207), ["How can I install python opencv on Heroku?"](http://stackoverflow.com/q/16949224/2419207) – iljau Feb 10 '14 at 21:14

1 Answers1

2

Apparently Python needs to be compiled with the --enable-shared flag passed in so that libpython2.7.so and libpython2.7.so.1.0 are created. OpenCV with the Python module requires libpython2.7.so.

To fix, compile python from source like so:

./configure --enable-shared
make
make install

Make sure to pass in the -D BUILD_NEW_PYTHON_SUPPORT=ON CMake flag when compiling OpenCV.

Nick Parsons
  • 8,377
  • 13
  • 48
  • 70