Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV 3.4.4 Python binding #13202

Closed
h6197627 opened this issue Nov 18, 2018 · 29 comments
Closed

OpenCV 3.4.4 Python binding #13202

h6197627 opened this issue Nov 18, 2018 · 29 comments

Comments

@h6197627
Copy link
Contributor

@h6197627 h6197627 commented Nov 18, 2018

In newly released OpenCV 3.4.4 python bindings installation process was changed. Now it creates new folder /usr/local/python with python binding stuff. To make it visible in python user should run setup script from this folder. However after installation I am getting error:

>>> import cv2
['/usr/local/lib/python3.6/dist-packages/opencv-3.4.4-py3.6.egg/cv2/../../python/cv2/python-3.6', '', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/local/lib/python3.6/dist-packages/scipy-1.1.0-py3.6-linux-x86_64.egg', '/usr/local/lib/python3.6/dist-packages/protobuf-3.6.1-py3.6-linux-x86_64.egg', '/usr/local/lib/python3.6/dist-packages/pycuda-2018.1.1-py3.6-linux-x86_64.egg', '/usr/local/lib/python3.6/dist-packages/Mako-1.0.7-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/appdirs-1.4.3-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/decorator-4.3.0-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/pytest-3.9.3-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/pytools-2018.5.2-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/MarkupSafe-1.0-py3.6-linux-x86_64.egg', '/usr/local/lib/python3.6/dist-packages/py-1.7.0-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/pluggy-0.8.0-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/more_itertools-4.3.0-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/attrs-18.2.0-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/atomicwrites-1.2.1-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/numpy-1.15.4-py3.6-linux-x86_64.egg', '/usr/local/lib/python3.6/dist-packages/opencv-3.4.4-py3.6.egg', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/opencv-3.4.4-py3.6.egg/cv2/__init__.py", line 89, in <module>
    bootstrap()
  File "/usr/local/lib/python3.6/dist-packages/opencv-3.4.4-py3.6.egg/cv2/__init__.py", line 79, in bootstrap
    import cv2
  File "/usr/local/lib/python3.6/dist-packages/opencv-3.4.4-py3.6.egg/cv2/__init__.py", line 89, in <module>
    bootstrap()
  File "/usr/local/lib/python3.6/dist-packages/opencv-3.4.4-py3.6.egg/cv2/__init__.py", line 23, in bootstrap
    raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

Also I have another question - is it possible to configure CMake to use only Ubuntu OS dedicated folders for python binding installation (/usr/local/lib/pythonX.X/dist-packages) without creating new non-standard directories (/usr/local/python)?

System information (version)
  • OpenCV => 3.4.4
  • Operating System / Platform => Ubuntu 18.04
  • Compiler => GCC
Steps to reproduce
  1. build OpenCV with python bindings
  2. cd /usr/local/python
  3. sudo python3 setup.py install
  4. python3
  5. import cv2

@alalek
Copy link
Contributor

@alalek alalek commented Nov 18, 2018

There are these options:

  1. Don't install this loader package (it is mostly for standalone distributions): #12977 (comment)

Old behavior can restored via these CMake variables:

  • OPENCV_SKIP_PYTHON_LOADER=ON
  • OPENCV_PYTHON3_INSTALL_PATH=...site/dist-packages location... (not required since #13254)
  1. setup.py is not complete for now and its usage is very limited (it is a bit tricky to install native binaries with their dependencies in Python). Try to install this loader in develop mode instead:
python3 setup.py develop
or
pip install -e .
  1. There is bug with paths:

opencv-3.4.4-py3.6.egg/cv2/../../python/cv2/python-3.6

should be

opencv-3.4.4-py3.6.egg/cv2/python-3.6

@alalek alalek self-assigned this Nov 18, 2018
iporty referenced this issue Nov 18, 2018
…oio (#13060)

* removed C API in the following modules: photo, video, imgcodecs, videoio

* trying to fix various compile errors and warnings on Windows and Linux

* continue to fix compile errors and warnings

* continue to fix compile errors, warnings, as well as the test failures

* trying to resolve compile warnings on Android

* Update cap_dc1394_v2.cpp

fix warning from the new GCC
@h6197627
Copy link
Contributor Author

@h6197627 h6197627 commented Nov 19, 2018

Thanks @alalek for helping! I will use old approach for now.

@wangqr
Copy link

@wangqr wangqr commented Nov 21, 2018

The printed path in the archlinux package includes '/build/opencv/src/build/lib/python3', which seems to be the building directory. Is this the expected behavior with the new loader?

@sergiomb2
Copy link
Contributor

@sergiomb2 sergiomb2 commented Dec 2, 2018

huf ! , you need do another release , install pyhton path are wrong , and just after a complete build we notice it, I spent one day to find it .

@tomrunia
Copy link

@tomrunia tomrunia commented Dec 12, 2018

I ran into the same error with OpenCV 4.0.0 on MacOS with Python 3.7.
This fixed it for me: python3 setup.py develop

@sergiomb2
Copy link
Contributor

@sergiomb2 sergiomb2 commented Dec 13, 2018

Old behavior can restored via these CMake variables:

OPENCV_SKIP_PYTHON_LOADER=ON

2 questions

  • Why this new behavior is default instead old behavior ?
  • What is the benefits of this new behavior ? ( which in Fedora packages seems that install python bindings in a not standard folder)
@edrozenberg
Copy link

@edrozenberg edrozenberg commented Dec 14, 2018

Ran into this also. Was not fun, and also my package created using make install DESTDIR now requires an additional non-standard, non-discoverable manual step to get the bindings set up after the package is installed on each target.

@dzhoshkun
Copy link

@dzhoshkun dzhoshkun commented Jan 19, 2019

I still get this error. The weird thing is, the following code runs fine:

import cv2

print('here')

when I run it using python3 tmp.py. But when I try to profile it using pprofile, i.e. pprofile tmp.py, I run into this error.

I'm using OpenCV 3.4.5, built from source.

Any ideas?

@sergiomb2
Copy link
Contributor

@sergiomb2 sergiomb2 commented Jan 19, 2019

ldd /usr/lib64/python2.7/site-packages/cv2.so should give you some clues

@dzhoshkun
Copy link

@dzhoshkun dzhoshkun commented Jan 20, 2019

Thanks @sergiomb2 for the quick response. Could you please provide some details about how ldd can help? Do you mean I should traverse the library dependency chain?

@sergiomb2
Copy link
Contributor

@sergiomb2 sergiomb2 commented Jan 20, 2019

cv2.so is a dinamic library , ldd can show you what from (python) cv2.so is not loading .
I.e. this scary error is not more than the cv2.so could not load dynamic libraries . So with ldd you can find out if is loads or not all dynamic libraries. You need see something like [1] to be sure that is not this bug

[1]

ldd /usr/lib64/python2.7/site-packages/cv2.so           
       linux-vdso.so.1 (0x00007ffddbff3000)
        libopencv_hdf.so.3.4 => /lib64/libopencv_hdf.so.3.4 (0x00007f350fba2000)
        libopencv_reg.so.3.4 => /lib64/libopencv_reg.so.3.4 (0x00007f350f97b000)
        libopencv_surface_matching.so.3.4 => /lib64/libopencv_surface_matching.so.3.4 (0x00007f350f72f000)
        libopencv_xphoto.so.3.4 => /lib64/libopencv_xphoto.so.3.4 (0x00007f350f4f3000)
        libopencv_freetype.so.3.4 => /lib64/libopencv_freetype.so.3.4 (0x00007f350f2eb000)
        libopencv_fuzzy.so.3.4 => /lib64/libopencv_fuzzy.so.3.4 (0x00007f350f0cf000)
        libopencv_hfs.so.3.4 => /lib64/libopencv_hfs.so.3.4 (0x00007f350eebc000)
        libopencv_img_hash.so.3.4 => /lib64/libopencv_img_hash.so.3.4 (0x00007f350eca3000)
        libopencv_shape.so.3.4 => /lib64/libopencv_shape.so.3.4 (0x00007f350ea6c000)
        libopencv_bioinspired.so.3.4 => /lib64/libopencv_bioinspired.so.3.4 (0x00007f350e827000)
        libopencv_line_descriptor.so.3.4 => /lib64/libopencv_line_descriptor.so.3.4 (0x00007f350e5fa000)
        libopencv_saliency.so.3.4 => /lib64/libopencv_saliency.so.3.4 (0x00007f350e3c7000)
        libopencv_ccalib.so.3.4 => /lib64/libopencv_ccalib.so.3.4 (0x00007f350e164000)
        libopencv_rgbd.so.3.4 => /lib64/libopencv_rgbd.so.3.4 (0x00007f350ded4000)
        libopencv_stitching.so.3.4 => /lib64/libopencv_stitching.so.3.4 (0x00007f350dc48000)
        libopencv_structured_light.so.3.4 => /lib64/libopencv_structured_light.so.3.4 (0x00007f350da2f000)
        libopencv_tracking.so.3.4 => /lib64/libopencv_tracking.so.3.4 (0x00007f350d5ef000)
        libopencv_aruco.so.3.4 => /lib64/libopencv_aruco.so.3.4 (0x00007f350d38c000)
        libopencv_bgsegm.so.3.4 => /lib64/libopencv_bgsegm.so.3.4 (0x00007f350d169000)
        libopencv_face.so.3.4 => /lib64/libopencv_face.so.3.4 (0x00007f350cecf000)
        libopencv_optflow.so.3.4 => /lib64/libopencv_optflow.so.3.4 (0x00007f350cc71000)
        libopencv_plot.so.3.4 => /lib64/libopencv_plot.so.3.4 (0x00007f350ca64000)
        libopencv_text.so.3.4 => /lib64/libopencv_text.so.3.4 (0x00007f350c737000)
        libopencv_ml.so.3.4 => /lib64/libopencv_ml.so.3.4 (0x00007f350c47c000)
        libopencv_dnn.so.3.4 => /lib64/libopencv_dnn.so.3.4 (0x00007f350bf10000)
        libopencv_photo.so.3.4 => /lib64/libopencv_photo.so.3.4 (0x00007f350bc44000)
        libopencv_objdetect.so.3.4 => /lib64/libopencv_objdetect.so.3.4 (0x00007f350b9cb000)
        libopencv_video.so.3.4 => /lib64/libopencv_video.so.3.4 (0x00007f350b75f000)
        libopencv_ximgproc.so.3.4 => /lib64/libopencv_ximgproc.so.3.4 (0x00007f350b318000)
        libopencv_calib3d.so.3.4 => /lib64/libopencv_calib3d.so.3.4 (0x00007f350af78000)
        libopencv_features2d.so.3.4 => /lib64/libopencv_features2d.so.3.4 (0x00007f350aca3000)
        libopencv_flann.so.3.4 => /lib64/libopencv_flann.so.3.4 (0x00007f350aa4b000)
        libopencv_highgui.so.3.4 => /lib64/libopencv_highgui.so.3.4 (0x00007f350a804000)
        libopencv_videoio.so.3.4 => /lib64/libopencv_videoio.so.3.4 (0x00007f350a5b1000)
        libopencv_imgcodecs.so.3.4 => /lib64/libopencv_imgcodecs.so.3.4 (0x00007f350a369000)
        libopencv_imgproc.so.3.4 => /lib64/libopencv_imgproc.so.3.4 (0x00007f3509d69000)
        libopencv_core.so.3.4 => /lib64/libopencv_core.so.3.4 (0x00007f3509828000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f3509495000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f3509101000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f3508ee9000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f3508b2a000)
        libhdf5.so.10 => /lib64/libhdf5.so.10 (0x00007f350866d000)
        libgomp.so.1 => /lib64/libgomp.so.1 (0x00007f350843d000)
        libfreetype.so.6 => /usr/lib64/freetype-freeworld/libfreetype.so.6 (0x00007f3508186000)
        libharfbuzz.so.0 => /lib64/libharfbuzz.so.0 (0x00007f3507ee1000)
        libopencv_phase_unwrapping.so.3.4 => /lib64/libopencv_phase_unwrapping.so.3.4 (0x00007f3507cd6000)
        libtesseract.so.3 => /lib64/libtesseract.so.3 (0x00007f350751f000)
        libprotobuf.so.15 => /lib64/libprotobuf.so.15 (0x00007f350702d000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3506e0e000)
        libOpenGL.so.0 => /lib64/libOpenGL.so.0 (0x00007f3506be0000)
        libQt5Test.so.5 => /lib64/libQt5Test.so.5 (0x00007f3510607000)
        libQt5OpenGL.so.5 => /lib64/libQt5OpenGL.so.5 (0x00007f35105aa000)
        libQt5Widgets.so.5 => /lib64/libQt5Widgets.so.5 (0x00007f3506565000)
        libQt5Gui.so.5 => /lib64/libQt5Gui.so.5 (0x00007f3506068000)
        libQt5Core.so.5 => /lib64/libQt5Core.so.5 (0x00007f3505b7f000)
        libgstreamer-1.0.so.0 => /lib64/libgstreamer-1.0.so.0 (0x00007f3505841000)
        libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f35055ef000)
        libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f35052d7000)
        libgstapp-1.0.so.0 => /lib64/libgstapp-1.0.so.0 (0x00007f35050c7000)
        libgstriff-1.0.so.0 => /lib64/libgstriff-1.0.so.0 (0x00007f3504eb8000)
        libgstpbutils-1.0.so.0 => /lib64/libgstpbutils-1.0.so.0 (0x00007f3504c7f000)
        libunicap.so.2 => /lib64/libunicap.so.2 (0x00007f35049dc000)
        libucil.so.2 => /lib64/libucil.so.2 (0x00007f35047c4000)
        libdc1394.so.22 => /lib64/libdc1394.so.22 (0x00007f350454f000)
        libv4l1.so.0 => /lib64/libv4l1.so.0 (0x00007f3504349000)
        libv4l2.so.0 => /lib64/libv4l2.so.0 (0x00007f350413a000)
        libOpenNI.so => /lib64/libOpenNI.so (0x00007f3503eb7000)
        libjpeg.so.62 => /lib64/libjpeg.so.62 (0x00007f3503c4f000)
        libwebp.so.7 => /lib64/libwebp.so.7 (0x00007f35039e2000)
        libpng16.so.16 => /lib64/libpng16.so.16 (0x00007f35037ae000)
        libgdcmMSFF.so.2.8 => /lib64/libgdcmMSFF.so.2.8 (0x00007f35033e1000)
        libtiff.so.5 => /lib64/libtiff.so.5 (0x00007f3503169000)
        libjasper.so.4 => /lib64/libjasper.so.4 (0x00007f3502f0c000)
        libIlmImf-2_2.so.22 => /lib64/libIlmImf-2_2.so.22 (0x00007f3502a24000)
        libgdal.so.20 => /lib64/libgdal.so.20 (0x00007f350151d000)
        libgdcmDSED.so.2.8 => /lib64/libgdcmDSED.so.2.8 (0x00007f350126e000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f350106a000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f3500e62000)
        libGLX.so.0 => /lib64/libGLX.so.0 (0x00007f3500c30000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f3500a19000)
        libtbb.so.2 => /lib64/libtbb.so.2 (0x00007f35007db000)
        libva.so.2 => /lib64/libva.so.2 (0x00007f35005b8000)
        libopenblas.so.0 => /lib64/libopenblas.so.0 (0x00007f34fe09b000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3510498000)
        libsz.so.2 => /lib64/libsz.so.2 (0x00007f34fde98000)
        libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f34fdc87000)
        libgraphite2.so.3 => /lib64/libgraphite2.so.3 (0x00007f34fda5b000)
        liblept.so.5 => /lib64/liblept.so.5 (0x00007f34fd5cf000)
        libGLdispatch.so.0 => /lib64/libGLdispatch.so.0 (0x00007f34fd315000)
        libGL.so.1 => /lib64/libGL.so.1 (0x00007f34fd084000)
        libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007f34fcde6000)
        libicui18n.so.60 => /lib64/libicui18n.so.60 (0x00007f34fc927000)
        libicuuc.so.60 => /lib64/libicuuc.so.60 (0x00007f34fc565000)
        libicudata.so.60 => /lib64/libicudata.so.60 (0x00007f34fa9bc000)
        libpcre2-16.so.0 => /lib64/libpcre2-16.so.0 (0x00007f34fa743000)
        libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f34fa541000)
        libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f34fa33d000)
        libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f34fa0cc000)
        libffi.so.6 => /lib64/libffi.so.6 (0x00007f34f9ec3000)
        libgstbase-1.0.so.0 => /lib64/libgstbase-1.0.so.0 (0x00007f34f9c4d000)
        libgstaudio-1.0.so.0 => /lib64/libgstaudio-1.0.so.0 (0x00007f34f99d8000)
        liborc-0.4.so.0 => /lib64/liborc-0.4.so.0 (0x00007f34f975b000)
        libgsttag-1.0.so.0 => /lib64/libgsttag-1.0.so.0 (0x00007f34f951f000)
        libgstvideo-1.0.so.0 => /lib64/libgstvideo-1.0.so.0 (0x00007f34f9284000)
        libpangoft2-1.0.so.0 => /lib64/libpangoft2-1.0.so.0 (0x00007f34f906e000)
        libpango-1.0.so.0 => /lib64/libpango-1.0.so.0 (0x00007f34f8e27000)
        libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x00007f34f8be3000)
        libtheora.so.0 => /lib64/libtheora.so.0 (0x00007f34f8994000)
        libogg.so.0 => /lib64/libogg.so.0 (0x00007f34f878d000)
        libvorbis.so.0 => /lib64/libvorbis.so.0 (0x00007f34f8560000)
        libvorbisenc.so.2 => /lib64/libvorbisenc.so.2 (0x00007f34f82b7000)
        libasound.so.2 => /lib64/libasound.so.2 (0x00007f34f7fb5000)
        libraw1394.so.11 => /lib64/libraw1394.so.11 (0x00007f34f7da5000)
        libusb-1.0.so.0 => /lib64/libusb-1.0.so.0 (0x00007f34f7b8c000)
        libv4lconvert.so.0 => /lib64/libv4lconvert.so.0 (0x00007f34f7912000)
        libtinyxml.so.0 => /lib64/libtinyxml.so.0 (0x00007f34f76fa000)
        libgdcmIOD.so.2.8 => /lib64/libgdcmIOD.so.2.8 (0x00007f34f74ea000)
        libgdcmDICT.so.2.8 => /lib64/libgdcmDICT.so.2.8 (0x00007f34f708b000)
        libgdcmjpeg8.so.2.8 => /lib64/libgdcmjpeg8.so.2.8 (0x00007f34f6e62000)
        libgdcmjpeg12.so.2.8 => /lib64/libgdcmjpeg12.so.2.8 (0x00007f34f6c39000)
        libgdcmjpeg16.so.2.8 => /lib64/libgdcmjpeg16.so.2.8 (0x00007f34f6a10000)
        libopenjp2.so.7 => /lib64/libopenjp2.so.7 (0x00007f34f67bf000)
        libCharLS.so.1 => /lib64/libCharLS.so.1 (0x00007f34f6575000)
        libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f34f636e000)
        libjson-c.so.4 => /lib64/libjson-c.so.4 (0x00007f34f615f000)
        libgdcmCommon.so.2.8 => /lib64/libgdcmCommon.so.2.8 (0x00007f34f5f22000)
        libjbig.so.2.1 => /lib64/libjbig.so.2.1 (0x00007f34f5d16000)
        libImath-2_2.so.12 => /lib64/libImath-2_2.so.12 (0x00007f34f5b03000)
        libHalf.so.12 => /lib64/libHalf.so.12 (0x00007f34f58c0000)
        libIex-2_2.so.12 => /lib64/libIex-2_2.so.12 (0x00007f34f56a0000)
        libIexMath-2_2.so.12 => /lib64/libIexMath-2_2.so.12 (0x00007f34f549b000)
        libIlmThread-2_2.so.12 => /lib64/libIlmThread-2_2.so.12 (0x00007f34f5294000)
        libarmadillo.so.9 => /lib64/libarmadillo.so.9 (0x00007f34f5088000)
        libpoppler.so.73 => /lib64/libpoppler.so.73 (0x00007f34f4bb4000)
        libfreexl.so.1 => /lib64/libfreexl.so.1 (0x00007f34f49aa000)
        libgeos_c.so.1 => /lib64/libgeos_c.so.1 (0x00007f34f4774000)
        libodbc.so.2 => /lib64/libodbc.so.2 (0x00007f34f4503000)
        libodbcinst.so.2 => /lib64/libodbcinst.so.2 (0x00007f34f42ed000)
        libkmlbase.so.1 => /lib64/libkmlbase.so.1 (0x00007f34f40d0000)
        libkmldom.so.1 => /lib64/libkmldom.so.1 (0x00007f34f3e0e000)
        libkmlengine.so.1 => /lib64/libkmlengine.so.1 (0x00007f34f3bd3000)
        libkmlxsd.so.1 => /lib64/libkmlxsd.so.1 (0x00007f34f39bd000)
        libkmlregionator.so.1 => /lib64/libkmlregionator.so.1 (0x00007f34f37b1000)
        libexpat.so.1 => /lib64/libexpat.so.1 (0x00007f34f3576000)
        libxerces-c-3.2.so => /lib64/libxerces-c-3.2.so (0x00007f34f2fad000)
        libnetcdf.so.11 => /lib64/libnetcdf.so.11 (0x00007f34efba4000)
        libogdi.so.3 => /lib64/libogdi.so.3 (0x00007f34ef982000)
        libgif.so.7 => /lib64/libgif.so.7 (0x00007f34ef778000)
        libgeotiff.so.2 => /lib64/libgeotiff.so.2 (0x00007f34ef546000)
        libgta.so.0 => /lib64/libgta.so.0 (0x00007f34ef33b000)
        libcfitsio.so.5 => /lib64/libcfitsio.so.5 (0x00007f34eef60000)
        libpq.so.5 => /lib64/libpq.so.5 (0x00007f34eed17000)
        libtirpc.so.3 => /lib64/libtirpc.so.3 (0x00007f34eeae5000)
        libdapclient.so.6 => /lib64/libdapclient.so.6 (0x00007f34ee8a2000)
        libdapserver.so.7 => /lib64/libdapserver.so.7 (0x00007f34ee692000)
        libdap.so.23 => /lib64/libdap.so.23 (0x00007f34ee300000)
        libspatialite.so.7 => /lib64/libspatialite.so.7 (0x00007f34edb84000)
        libsqlite3.so.0 => /lib64/libsqlite3.so.0 (0x00007f34ed87f000)
        libcurl.so.4 => /lib64/libcurl.so.4 (0x00007f34ed5f7000)
        libxml2.so.2 => /lib64/libxml2.so.2 (0x00007f34ed290000)
        liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f34ed069000)
        libmariadb.so.3 => /lib64/libmariadb.so.3 (0x00007f34ece17000)
        libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007f34ecbaa000)
        libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f34ec719000)
        libX11.so.6 => /lib64/libX11.so.6 (0x00007f34ec3d8000)
        libXext.so.6 => /lib64/libXext.so.6 (0x00007f34ec1c6000)
        libgfortran.so.5 => /lib64/libgfortran.so.5 (0x00007f34ebd4c000)
        libaec.so.0 => /lib64/libaec.so.0 (0x00007f34ebb44000)
        liblz4.so.1 => /lib64/liblz4.so.1 (0x00007f34eb92d000)
        libcap.so.2 => /lib64/libcap.so.2 (0x00007f34eb728000)
        libmount.so.1 => /lib64/libmount.so.1 (0x00007f34eb4ce000)
        libgcrypt.so.20 => /lib64/libgcrypt.so.20 (0x00007f34eb1b3000)
        libthai.so.0 => /lib64/libthai.so.0 (0x00007f34eafa9000)
        libfribidi.so.0 => /lib64/libfribidi.so.0 (0x00007f34ead8d000)
        libudev.so.1 => /lib64/libudev.so.1 (0x00007f34eab67000)
        libgdcmmd5.so.2.8 => /lib64/libgdcmmd5.so.2.8 (0x00007f34ea964000)
        libssl.so.10 => /lib64/libssl.so.10 (0x00007f34ea6f6000)
        libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f34ea294000)
        libopenblaso.so.0 => /lib64/libopenblaso.so.0 (0x00007f34e7c11000)
        liblapack.so.3 => /lib64/liblapack.so.3 (0x00007f34e7376000)
        libarpack.so.2 => /lib64/libarpack.so.2 (0x00007f34e712a000)
        libsuperlu.so.5.1 => /lib64/libsuperlu.so.5.1 (0x00007f34e6eb4000)
        libsmime3.so => /lib64/libsmime3.so (0x00007f34e6c8c000)
        libnss3.so => /lib64/libnss3.so (0x00007f34e6960000)
        libnspr4.so => /lib64/libnspr4.so (0x00007f34e6720000)
        liblcms2.so.2 => /lib64/liblcms2.so.2 (0x00007f34e64c4000)
        libgeos-3.6.1.so => /lib64/libgeos-3.6.1.so (0x00007f34e60df000)
        libltdl.so.7 => /lib64/libltdl.so.7 (0x00007f34e5ed5000)
        libminizip.so.1 => /lib64/libminizip.so.1 (0x00007f34e5cc9000)
        liburiparser.so.1 => /lib64/liburiparser.so.1 (0x00007f34e5aaa000)
        libkmlconvenience.so.1 => /lib64/libkmlconvenience.so.1 (0x00007f34e5889000)
        libhdf5_hl.so.10 => /lib64/libhdf5_hl.so.10 (0x00007f34e5667000)
        libproj.so.12 => /lib64/libproj.so.12 (0x00007f34e53fd000)
        libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f34e51ae000)
        libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007f34e4f51000)
        libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f34e4c64000)
        libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f34e4a48000)
        libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f34e4844000)
        libnghttp2.so.14 => /lib64/libnghttp2.so.14 (0x00007f34e461e000)
        libidn2.so.0 => /lib64/libidn2.so.0 (0x00007f34e4401000)
        libssh.so.4 => /lib64/libssh.so.4 (0x00007f34e4182000)
        libpsl.so.5 => /lib64/libpsl.so.5 (0x00007f34e3f71000)
        libldap-2.4.so.2 => /lib64/libldap-2.4.so.2 (0x00007f34e3d1d000)
        liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007f34e3b0e000)
        libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f34e38e5000)
        libquadmath.so.0 => /lib64/libquadmath.so.0 (0x00007f34e36a5000)
        libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f34e3454000)
        libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f34e322b000)
        libgpg-error.so.0 => /lib64/libgpg-error.so.0 (0x00007f34e300b000)
        libdatrie.so.1 => /lib64/libdatrie.so.1 (0x00007f34e2e04000)
        libblas.so.3 => /lib64/libblas.so.3 (0x00007f34e2bb0000)
        libopenblasp.so.0 => /lib64/libopenblasp.so.0 (0x00007f34e052a000)
        libsatlas.so.3 => /usr/lib64/atlas/libsatlas.so.3 (0x00007f34df75b000)
        libnssutil3.so => /lib64/libnssutil3.so (0x00007f34df52b000)
        libplc4.so => /lib64/libplc4.so (0x00007f34df326000)
        libplds4.so => /lib64/libplds4.so (0x00007f34df122000)
        libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f34def13000)
        libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f34ded0f000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f34deaf8000)
        libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007f34de8db000)
        libssl3.so => /lib64/libssl3.so (0x00007f34de685000)
        libunistring.so.2 => /lib64/libunistring.so.2 (0x00007f34de304000)
        libXau.so.6 => /lib64/libXau.so.6 (0x00007f34de100000)
        libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f34dde7c000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f34ddc43000)
@dzhoshkun
Copy link

@dzhoshkun dzhoshkun commented Jan 21, 2019

Turns out there are two copies of the cv2.so shared library:

  • one directly under /usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so
  • and the second under /usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so

In addition there's a /usr/local/lib/python3.6/dist-packages/cv2/__init__.py file with the bootstrap function where the "recursion is detected". Not entirely sure but this folder might've been created while installing OpenCV via the Ubuntu repositories (apt install ...). What leads me to this conclusion is that this folder is not touched when I do a make uninstall of OpenCV from source. In this case removing this folder seems to solve the problem. That is, now pprofile tmp.py seems to run fine as well.

@alalek
Copy link
Contributor

@alalek alalek commented Jan 21, 2019

Compare timestamps of these files. They should differ. Remove (rename) old file to avoid conflicts.

/usr/local/lib
Ubuntu repositories

They should not install into /usr/local

make uninstall

It doesn't work well if you amend your build directory. Due this limitation, using of "sudo make install" is not recommended.

@dzhoshkun
Copy link

@dzhoshkun dzhoshkun commented Jan 21, 2019

Thanks @alalek What's the best way to uninstall an OpenCV built from source cleanly? Is it simply to override the installation with a fresh make install ?

@dzhoshkun
Copy link

@dzhoshkun dzhoshkun commented Jan 21, 2019

Sorry my question is rather paradoxical, I've noticed... What I mean is, is there a guide to cleanly uninstall OpenCV, listing all the required (possibly manual) steps?

@alalek
Copy link
Contributor

@alalek alalek commented Jan 21, 2019

For development - consider using OpenCV build folder without any installation (in case of CMake: cmake -DOpenCV_DIR=<build_dir> ...).
For non-development purposes use package managers.

https://askubuntu.com/questions/264211/why-do-people-say-make-install-is-bad

uninstall an OpenCV built from source cleanly

This is the main problem. Files from old source version are not removed, new files are silently overrides existed one.

@BasinChen
Copy link

@BasinChen BasinChen commented Jan 29, 2019

raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
It doesn't work on my PC
Windows 10
python3.7
what should I do

@KernelA
Copy link

@KernelA KernelA commented Jun 25, 2019

raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
It doesn't work on my PC
Windows 10
python3.7
what should I do

I have same issue. I compile OpenCV 4.1.0 from source.
Windows 10 1809
Python 3.7.2

@alalek
Copy link
Contributor

@alalek alalek commented Jun 25, 2019

Provide reproducer steps and expected/actual results:

  • CMake command line args
  • CMake stdout (from clean build)
  • build logs (install part if used)
  • loader's dump with debug flag:
python -c 'import sys; sys.OpenCV_LOADER_DEBUG = 1; import cv2 as cv; print(cv.getBuildInformation()); print(cv.__file__)'

Unfortunately, without a reproducer on our side, we can't investigate this.

@132ikl
Copy link

@132ikl 132ikl commented Jul 12, 2019

Hello, I am also having this issue. Setting OPENCV_SKIP_PYTHON_LOADER=ON seems to have no effect whatsoever, and there aren't any setup.py files.
CMake command line args

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/opt/opencv-4.1.0 \
    -D CMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D PYTHON3_INCLUDE_PATH=/usr/include/python3.7m \
    -D PYTHON3_LIBRARIES=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so \
    -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \
    -D BUILD_OPENCV_PYTHON3=ON \
    -D ENABLE_NEON=ON \
    -D ENABLE_VFPV3=ON \
    -D WIDTH_GTK=OFF \
    -D BUILD_TESTS=OFF \
    -D BUILD_DOCS=OFF \
    -D BUILD_EXAMPLES=OFF ..

CMake stdout: https://fs.ikl.sh/selif/opencvout.txt
Build logs: https://fs.ikl.sh/selif/buildlogs.txt
Loader's dump with debug flag:

python3 -c 'import sys; sys.OpenCV_LOADER_DEBUG = 1; import cv2 as cv; print(cv.getBuildInformation()); print(cv.__file__)'
OpenCV loader: os.name="posix"  platform.system()="Linux"
OpenCV loader: loading config: /opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/config.py
OpenCV loader: loading config: /opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/config-3.7.py
OpenCV loader: PYTHON_EXTENSIONS_PATHS=['/opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/python-3.7']
OpenCV loader: BINARIES_PATHS=['/opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/../../../../lib']
OpenCV loader: replacing cv2 module
['', '/opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/python-3.7', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/lib/python3/dist-packages']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/__init__.py", line 89, in <module>
    bootstrap()
  File "/opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/__init__.py", line 79, in bootstrap
    import cv2
  File "/opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/__init__.py", line 89, in <module>
    bootstrap()
  File "/opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/__init__.py", line 23, in bootstrap
    raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

Thanks :)

@alalek
Copy link
Contributor

@alalek alalek commented Jul 12, 2019

Setting OPENCV_SKIP_PYTHON_LOADER=ON seems to have no effect

This is really strange - there are no extra conditions to ignore this flag.

  1. Add message("! OPENCV_SKIP_PYTHON_LOADER=${OPENCV_SKIP_PYTHON_LOADER}") somewhere (the first line of root CMakeLists.txt is enough). Re-run cmake and check dump of this string.
  2. You don't have this parameter in your CMake's command line.
  3. "make install" has one serious problem. There is no "uninstall" command issued automatically. This may cause mess.

From buildlogs.txt:

--   Platform:
--     Timestamp:                   2019-07-12T04:00:12Z
--     Host:                        Linux 5.1.16-arch1-1-ARCH x86_64
--     Target:                      Linux 1 arm
--     CMake:                       3.13.4
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE

...

-- Installing: /opt/opencv-4.1.0/lib/python3.7/dist-packages/cv2/python-3.7/
   cv2.cpython-37m-x86_64-linux-gnu.so

cv2 suffix is wrong for ARM target (.cpython-37m-x86_64-linux-gnu.so).
It is necessary to specify PYTHON3_CVPY_SUFFIX in case of cross-compilation (for both variants with/without loader).
Correct value can be found from this command (from the target system):
(python3 -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('EXT_SUFFIX'))").


BUILD_OPENCV_PYTHON3=ON

CMake vars are case sensitive: BUILD_opencv_python3=ON

CMAKE_BUILD_TYPE=RELEASE

Values too: Release

WIDTH_GTK

typo

-D BUILD_TESTS=OFF

Make sense to add this too: BUILD_PERF_TESTS=OFF too

@132ikl
Copy link

@132ikl 132ikl commented Jul 12, 2019

I didn't have the parameter, however even when I include it setup.py does not exist.

I will try the rest later. Thanks.

@132ikl
Copy link

@132ikl 132ikl commented Jul 17, 2019

Hi, sorry for the wait. I am now recieving Segmentation fault as soon as I try to import cv2 in Python 3. This is with Python loader enabled, however I can try with Python loader disable if you think it will help. If this is a separate issue, I can make a new issue report.

CMake Command:

    -D CMAKE_INSTALL_PREFIX="${ROOTFS_DIR}/usr/local" \
    -D CMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D PYTHON3_INCLUDE_PATH=/usr/include/python3.7m \
    -D PYTHON3_LIBRARIES=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so \
    -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include \
    -D BUILD_opencv_python3=ON \
    -D PYTHON3_CVPY_SUFFIX='.cpython-37m-arm-linux-gnueabihf.so' \
    -D ENABLE_NEON=ON \
    -D ENABLE_VFPV3=ON \
    -D WITH_GTK=OFF \
    -D BUILD_TESTS=OFF \
    -D BUILD_DOCS=OFF \
    -D BUILD_EXAMPLES=OFF \
    -D BUILD_PERF_TESTS=OFF \
    -B "${CV_DIR}/build/" \
    -S "${CV_DIR}"

CMake Output: https://ikl.sh/c6d6
Make Output: https://ikl.sh/oQTA
Make Install Output: https://ikl.sh/QDrB

Thanks :)

@132ikl
Copy link

@132ikl 132ikl commented Jul 18, 2019

Hi, disregard everything above. The reason why it wasn't working was because I was using QEMU for the ARM guest and for some reason it didn't work in QEMU, but it did work on real hardware. Thank you for helping me out before @alalek!

@zchrissirhcz
Copy link
Contributor

@zchrissirhcz zchrissirhcz commented Nov 18, 2019

This python binding issue also occur in opencv4.1.0, with python3.7.3 from miniconda.

And the python setup.py develop works for me.

As python2 will retire in 2020, wish opencv's python interface installation could be fixed soon.

@ArghyaChatterjee
Copy link

@ArghyaChatterjee ArghyaChatterjee commented Apr 14, 2020

I also got the same error message. I solved it by renaming cv2.so.3.4.8 dll to cv2.so inside the /usr/local/lib/python3.6/dist-packages/cv2/python-3.6 directory. At first, I was a little bit of adventurous to follow adrian in pyimagesearch's comments on naming cv2.so files according to version names. It was actually my mistake.
The blog of adrian that I followed during installation was this one: https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/

@Nukul13
Copy link

@Nukul13 Nukul13 commented Aug 17, 2020

I also got the same error message. I solved it by renaming cv2.so.3.4.8 dll to cv2.so inside the /usr/local/lib/python3.6/dist-packages/cv2/python-3.6 directory. At first, I was a little bit of adventurous to follow adrian in pyimagesearch's comments on naming cv2.so files according to version names. It was actually my mistake.
The blog of adrian that I followed during installation was this one: https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/

Also there is no need to create a symlink for the same. This worked for me in opencv-4.4.0

@chrisg123
Copy link

@chrisg123 chrisg123 commented Feb 9, 2021

I also got the same error message. I solved it by renaming cv2.so.3.4.8 dll to cv2.so inside the /usr/local/lib/python3.6/dist-packages/cv2/python-3.6 directory. At first, I was a little bit of adventurous to follow adrian in pyimagesearch's comments on naming cv2.so files according to version names. It was actually my mistake.
The blog of adrian that I followed during installation was this one: https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/

This solved it for me! I am cross compiling for a raspberrypi and the library was named cv2.cpython-37m-x86_64-linux-gnu.so renaming this to just cv2.so solved ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions.

@eltonfernando
Copy link

@eltonfernando eltonfernando commented Apr 9, 2021

solved for min. I copy cv2.cpython-38-x86_64-linux-gnu.so in my work. It also resolves if you are trying to compile with pyinstaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet