Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Build OpenCV for Python

Dears,

I'm trying to build OpenCV including with CMAKE option "BUILD_opencv_python2" - I finshed always with errors:

CMAKE configurtion says:

Detected version of GNU GCC: 53 (503)
CUDA compilation is disabled (due to only Visual Studio compiler supported on your platform).
Could NOT find PythonInterp: Found unsuitable version "2.7.10", but required is at least "3.4" (found C:/Python27/python.exe)
Could NOT find PythonInterp: Found unsuitable version "2.7.10", but required is at least "3.2" (found C:/Python27/python.exe)

General configuration for OpenCV 3.1.0-dev =====================================
  Version control:               1cd3c6f

  Platform:
    Host:                        Windows 6.1.7601 AMD64
    CMake:                       3.4.2
    CMake generator:             MinGW Makefiles
    CMake build tool:            C:/mingw-w64/i686-5.3.0-posix-dwarf-rt_v4-rev0/mingw32/bin/mingw32-make.exe
    Configuration:               Release
  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/mingw-w64/i686-5.3.0-posix-dwarf-rt_v4-rev0/mingw32/bin/g++.exe  (ver 5.3.0)
    C++ flags (Release):         -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O2 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  C:/mingw-w64/i686-5.3.0-posix-dwarf-rt_v4-rev0/mingw32/bin/gcc.exe
    C flags (Release):           -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -fvisibility=hidden -O2 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      
    Linker flags (Debug):        
    Precompiled headers:         YES
    Extra dependencies:          comctl32 gdi32 ole32 setupapi ws2_32 vfw32 winmm
    3rdparty dependencies:       zlib libjpeg libwebp libpng libtiff libjasper IlmImf

  OpenCV modules:
    To be built:                 core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d stitching videostab python2
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python3 viz

  Python 2:
    Interpreter:                 C:/Python27/python.exe (ver 2.7.10)
    Libraries:                   C:/Python27/libs/libpython27.a (ver 2.7.10+)
    numpy:                       C:/Python27/Lib/site-packages/numpy/core/include (ver 1.9.2)
    packages path:               C:/Python27/Lib/site-packages

  Python (for build):            C:/Python27/python.exe

I have installed python, numpy - it's working.

First question: Do not understand why CMAKE says: Found unsuitable version "2.7.10", but required is at least "3.4" ?

Secondly - when "make" runs to build it ends up with:

[ 98%] Linking CXX shared module ..\..\lib\cv2.pyd
C:/Python27/libs/libpython27.a: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
modules\python2\CMakeFiles\opencv_python2.dir\build.make:226: recipe for target 'lib/cv2.pyd' failed
mingw32-make[2]: *** [lib/cv2.pyd] Error 1
CMakeFiles\Makefile2:7265: recipe for target 'modules/python2/CMakeFiles/opencv_python2.dir/all' failed
mingw32-make[1]: *** [modules/python2/CMakeFiles/opencv_python2.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

Question: Looking for way what's wrong and what to do differently if want to have successful OpenCV for Python?

Thank you.

Best regards,

Peter