opencv / opencv-python

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
https://pypi.org/project/opencv-python/
MIT License
4.53k stars 847 forks source link

ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation. #680

Open mrjeckel opened 2 years ago

mrjeckel commented 2 years ago

Seeing a similar issue to https://github.com/opencv/opencv-python/issues/432 with opencv-python==4.6.0.66 packaged using pyinstaller==4.4. It works fine when running from source; the issue only occurs when packaged. opencv-python==4.5.5.64 works fine.

My Env: Ubuntu 16 Python3.8 opencv-python==4.6.0.66 pyinstaller==4.4

Traceback (most recent call last):
  File "ftf_app_bambam.py", line 2, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "taskmaster/app_manager.py", line 30, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "hardware/ximea_camera/setup_tools/filter_tuning.py", line 9, in <module>
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib/__init__.py", line 127, in import_module
    applySysPathWorkaround = True
  File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
  File "cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "cv2/__init__.py", line 76, 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.
[11606] Failed to execute script 'ftf_app_bambam' due to unhandled exception!
SeungjunNah commented 2 years ago

Same here. I also had to revert to 4.5.5.64

asenyaev commented 2 years ago

Hi @mrjeckel, @SeungjunNah!

I've tried to reproduce the issue on my Ubuntu 18.04 installing Python3.8, opencv-python==4.6.0.66 and pyinstaller==4.4, but anything passed successfully.

My reproducing steps:

  1. Install opencv-python==4.6.0.66:
    python3.8 -m pip install --force-reinstall --no-cache opencv-python==4.6.0.66
  2. Install pyinstaller==4.4:
    python3.8 -m pip install --force-reinstall --no-cache pyinstaller==4.4
  3. Create py script:

test.py

import cv2

if __name__ == '__main__':
    print("Hello, world!")
  1. Use pyinstaller with this script:
    pyinstaller --onefile test.py
Output ```49 INFO: PyInstaller: 4.4 49 INFO: Python: 3.8.13 62 INFO: Platform: Linux-5.4.0-109-generic-x86_64-with-glibc2.27 63 INFO: wrote /home/user/test/test.spec 65 INFO: UPX is not available. 66 INFO: Extending PYTHONPATH with paths ['/home/user/test', '/home/user/test'] 71 INFO: checking Analysis 71 INFO: Building Analysis because Analysis-00.toc is non existent 71 INFO: Initializing module dependency graph... 72 INFO: Caching module graph hooks... 80 INFO: Analyzing base_library.zip ... 2230 INFO: Processing pre-find module path hook distutils from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'. 2231 INFO: distutils: retargeting to non-venv dir '/usr/lib/python3.8' 4462 INFO: Caching module dependency graph... 4640 INFO: running Analysis Analysis-00.toc 4663 INFO: Analyzing /home/user/test/test.py 6944 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-setuptools.extern.six.moves.py'. 7311 INFO: Processing pre-find module path hook site from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-site.py'. 7312 INFO: site: retargeting to fake-dir '/home/user/.local/lib/python3.8/site-packages/PyInstaller/fake-modules' 10302 INFO: Processing module hooks... 10302 INFO: Loading module hook 'hook-cv2.py' from '/home/user/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'... 10303 INFO: Loading module hook 'hook-py.py' from '/home/user/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'... 10648 INFO: Loading module hook 'hook-pycparser.py' from '/home/user/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'... 10649 INFO: Loading module hook 'hook-pytest.py' from '/home/user/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'... 10931 INFO: Loading module hook 'hook-numpy._pytesttester.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 10933 INFO: Loading module hook 'hook-lib2to3.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 10939 INFO: Loading module hook 'hook-encodings.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11005 INFO: Loading module hook 'hook-pkg_resources.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11495 INFO: Processing pre-safe import module hook win32com from '/home/user/.local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/pre_safe_import_module/hook-win32com.py'. 11497 WARNING: Hidden import "pkg_resources.py2_warn" not found! 11497 WARNING: Hidden import "pkg_resources.markers" not found! 11500 INFO: Loading module hook 'hook-_tkinter.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11593 INFO: checking Tree 11593 INFO: Building Tree because Tree-00.toc is non existent 11593 INFO: Building Tree Tree-00.toc 11600 INFO: checking Tree 11600 INFO: Building Tree because Tree-01.toc is non existent 11600 INFO: Building Tree Tree-01.toc 11646 WARNING: Tcl modules directory /usr/share/tcltk/tcl8.6/../tcl8 does not exist. 11647 INFO: Loading module hook 'hook-scipy.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11648 INFO: Loading module hook 'hook-sysconfig.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11660 INFO: Loading module hook 'hook-numpy.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11720 INFO: Import to be excluded not found: 'f2py' 11743 INFO: Loading module hook 'hook-xml.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11743 INFO: Loading module hook 'hook-difflib.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11746 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11747 INFO: Loading module hook 'hook-pickle.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 11750 INFO: Loading module hook 'hook-setuptools.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12203 INFO: Loading module hook 'hook-setuptools.msvc.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12208 INFO: Loading module hook 'hook-distutils.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12208 INFO: Loading module hook 'hook-zope.interface.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12211 INFO: Loading module hook 'hook-distutils.util.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12214 INFO: Loading module hook 'hook-xml.dom.domreg.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12214 INFO: Loading module hook 'hook-packaging.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12214 INFO: Loading module hook 'hook-heapq.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12218 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks'... 12238 INFO: Looking for ctypes DLLs 12345 INFO: Analyzing run-time hooks ... 12349 INFO: Including run-time hook '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgutil.py' 12351 INFO: Including run-time hook '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py' 12353 INFO: Including run-time hook '/home/user/.local/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_inspect.py' 12363 INFO: Looking for dynamic libraries 12946 INFO: Looking for eggs 12946 INFO: Python library not in binary dependencies. Doing additional searching... 13003 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0 13013 INFO: Warnings written to /home/user/test/build/test/warn-test.txt 13072 INFO: Graph cross-reference written to /home/user/test/build/test/xref-test.html 13093 INFO: checking PYZ 13093 INFO: Building PYZ because PYZ-00.toc is non existent 13093 INFO: Building PYZ (ZlibArchive) /home/user/test/build/test/PYZ-00.pyz 13599 INFO: Building PYZ (ZlibArchive) /home/user/test/build/test/PYZ-00.pyz completed successfully. 13604 INFO: checking PKG 13604 INFO: Building PKG because PKG-00.toc is non existent 13604 INFO: Building PKG (CArchive) PKG-00.pkg 20729 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully. 20730 INFO: Bootloader /home/user/.local/lib/python3.8/site-packages/PyInstaller/bootloader/Linux-64bit-intel/run 20731 INFO: checking EXE 20731 INFO: Building EXE because EXE-00.toc is non existent 20731 INFO: Building EXE from EXE-00.toc 20731 INFO: Appending archive to ELF section in EXE /home/user/test/dist/test 20766 INFO: Building EXE from EXE-00.toc completed successfully.
asenyaev commented 2 years ago

I also tried to do the same steps in a container with Ubuntu 16, and it also finished successfully.

Output Ubuntu 16 ```85 INFO: PyInstaller: 4.4 85 INFO: Python: 3.8.3 86 INFO: Platform: Linux-5.4.0-109-generic-x86_64-with-glibc2.2.5 86 INFO: wrote /io/test.spec 88 INFO: UPX is not available. 89 INFO: Extending PYTHONPATH with paths ['/io', '/io'] 171 INFO: checking Analysis 172 INFO: Building Analysis because Analysis-00.toc is non existent 172 INFO: Initializing module dependency graph... 174 INFO: Caching module graph hooks... 186 WARNING: Several hooks defined for module 'numpy'. Please take care they do not conflict. 191 INFO: Analyzing base_library.zip ... 2568 INFO: Processing pre-find module path hook distutils from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'. 2602 INFO: distutils: retargeting to non-venv dir '/usr/local/lib/python3.8' 4837 INFO: Caching module dependency graph... 5019 INFO: running Analysis Analysis-00.toc 5034 INFO: Analyzing /io/test.py 6274 INFO: Processing pre-find module path hook site from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-site.py'. 6274 INFO: site: retargeting to fake-dir '/usr/local/lib/python3.8/site-packages/PyInstaller/fake-modules' 8312 INFO: Processing module hooks... 8312 INFO: Loading module hook 'hook-cv2.py' from '/usr/local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'... 8314 INFO: Loading module hook 'hook-numpy.py' from '/usr/local/lib/python3.8/site-packages/numpy/_pyinstaller'... 8340 INFO: Import to be excluded not found: 'f2py' 8385 INFO: Loading module hook 'hook-numpy._pytesttester.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 8387 INFO: Loading module hook 'hook-lib2to3.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 8419 INFO: Loading module hook 'hook-encodings.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 8465 INFO: Loading module hook 'hook-pkg_resources.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 8630 INFO: Processing pre-safe import module hook win32com from '/usr/local/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/pre_safe_import_module/hook-win32com.py'. 9104 WARNING: Hidden import "pkg_resources.py2_warn" not found! 9104 WARNING: Hidden import "pkg_resources.markers" not found! 9107 INFO: Loading module hook 'hook-_tkinter.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 9166 INFO: checking Tree 9172 INFO: checking Tree 9210 WARNING: Tcl modules directory /usr/share/tcltk/tcl8.6/../tcl8 does not exist. 9211 INFO: Loading module hook 'hook-sysconfig.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 9222 INFO: Loading module hook 'hook-xml.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 9274 INFO: Loading module hook 'hook-difflib.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 9276 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 9277 INFO: Loading module hook 'hook-pickle.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 9279 INFO: Loading module hook 'hook-setuptools.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 10034 INFO: Loading module hook 'hook-setuptools.msvc.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 10037 INFO: Loading module hook 'hook-distutils.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 10037 INFO: Loading module hook 'hook-distutils.util.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 10039 INFO: Loading module hook 'hook-heapq.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 10041 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks'... 10058 INFO: Looking for ctypes DLLs 10167 INFO: Analyzing run-time hooks ... 10172 INFO: Including run-time hook '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgutil.py' 10174 INFO: Including run-time hook '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py' 10177 INFO: Including run-time hook '/usr/local/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_inspect.py' 10188 INFO: Looking for dynamic libraries 10850 INFO: Looking for eggs 10850 INFO: Using Python library /root/Python-3.8.3/libpython3.8.so.1.0 10862 INFO: Warnings written to /io/build/test/warn-test.txt 10913 INFO: Graph cross-reference written to /io/build/test/xref-test.html 10930 INFO: checking PYZ 10930 INFO: Building PYZ because PYZ-00.toc is non existent 10930 INFO: Building PYZ (ZlibArchive) /io/build/test/PYZ-00.pyz 11454 INFO: Building PYZ (ZlibArchive) /io/build/test/PYZ-00.pyz completed successfully. 11460 INFO: checking PKG 11460 INFO: Building PKG because PKG-00.toc is non existent 11460 INFO: Building PKG (CArchive) PKG-00.pkg 23789 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully. 23792 INFO: Bootloader /usr/local/lib/python3.8/site-packages/PyInstaller/bootloader/Linux-64bit-intel/run 23792 INFO: checking EXE 23792 INFO: Building EXE because EXE-00.toc is non existent 23792 INFO: Building EXE from EXE-00.toc 23793 INFO: Appending archive to ELF section in EXE /io/dist/test 23854 INFO: Building EXE from EXE-00.toc completed successfully.
asenyaev commented 2 years ago

It can be something wrong with a local environment on your side. Could you check which OpenCV Python packages were installed using pip:

python3.8 -m pip list | grep -i opencv

Multiple OpenCV Python packages can break your environment. Please, use only one package at a time. In addition, I would suggest to use --force-reinstall flag for pip to be sure that re-installation happened.

noword commented 2 years ago

I use Windows 10, python 3.8, newest version of opencv-python. When I try to pack a exe with pyinstaller, I have the exact same problem. opencv-python==4.5.5.64 works fine.

I compared two version of init.py Maybe the key is in line 162: 4.5.5.64: native_module = importlib.import_module("cv2.cv2") 4.6.0.66: native_module = importlib.import_module("cv2")

AeonDave commented 2 years ago

I have the same problem however it only appears if I run my python project in trace mode python 3.8 opencv-contrib-python 4.6.0.66

python3 -u -m trace -c run.py

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.8/trace.py", line 756, in <module>
    main()
  File "/usr/lib/python3.8/trace.py", line 744, in main
    t.runctx(code, globs, globs)
  File "/usr/lib/python3.8/trace.py", line 450, in runctx
    exec(cmd, globals, locals)
  File "run.py", line 7, in <module>
    from apps import app
  File "/home/user/Projects/test/apps/__init__.py", line 8, in <module>
    from argo.services.source_service import SourceService
  File "/home/user/Projects/test/argo/services/source_service.py", line 4, in <module>
    import cv2
  File "/home/user/.local/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/user/.local/lib/python3.8/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/user/.local/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/user/.local/lib/python3.8/site-packages/cv2/__init__.py", line 76, 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.

otherwise it works normally

evgenii-d commented 2 years ago

Same problem on Windows 11 with Python 3.10.2, numpy==1.23.1, pyinstaller==5.2 and opencv-python==4.6.0.66

['C:\\Users\\a13\\Desktop\\build\\dist\\timelapse\\base_library.zip', 'C:\\Users\\a13\\Desktop\\build\\dist\\timelapse\\cv2', 'C:\\Users\\a13\\Desktop\\build\\dist\\timelapse\\lib-dynload', 'C:\\Users\\a13\\Desktop\\build\\dist\\timelapse'] Traceback (most recent call last): File "main.py", line 6, in <module> import cv2 File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "cv2\__init__.py", line 181, in <module> bootstrap() File "cv2\__init__.py", line 153, in bootstrap native_module = importlib.import_module("cv2") File "importlib\__init__.py", line 126, in import_module if sys.path[0] == BASE_DIR or os.path.realpath(sys.path[0]) == BASE_DIR: File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "cv2\__init__.py", line 181, in <module> bootstrap() File "cv2\__init__.py", line 76, 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.

With opencv-python==4.5.5.64 works like a charm.

gauthierbuttez commented 2 years ago

Environment:

Windows 10

PyInstaller: 5.2

Python: 3.10.5

opencv-python 4.6.0.66

Problem:

I am trying to compile my Python code with PyInstaller. The exe is created and when I execute it, I get this error message:

Traceback (most recent call last):
  File "PhoneBot.py", line 343, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "modules\prepare_envir_appium.py", line 24, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "modules\mymodulesteam.py", line 13, in <module>
  File "C:\Users\gauth\AppData\Local\Temp\_MEI40002\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\gauth\AppData\Local\Temp\_MEI40002\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib\__init__.py", line 126, in import_module
  File "C:\Users\gauth\AppData\Local\Temp\_MEI40002\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\gauth\AppData\Local\Temp\_MEI40002\cv2\__init__.py", line 76, 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.

What did I try:

I think I tried it all:

It didn't work

It didn't work

It didn't work

It didn't work

Here are the logs of PyInstaller if it can help:

130 INFO: PyInstaller: 5.2
130 INFO: Python: 3.10.5
268 INFO: Platform: Windows-10-10.0.19044-SP0
269 INFO: wrote C:\Users\gauth\Documents\project\project_debug3\project.spec
275 INFO: UPX is not available.
275 INFO: Removing temporary files and cleaning cache in C:\Users\gauth\AppData\Local\pyinstaller
353 INFO: Extending PYTHONPATH with paths
['C:\\Users\\gauth\\Documents\\project\\project_debug3',
 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\site-packages\\cv2']
1144 INFO: checking Analysis
1144 INFO: Building Analysis because Analysis-00.toc is non existent
1146 INFO: Initializing module dependency graph...
1152 INFO: Caching module graph hooks...
1162 WARNING: Several hooks defined for module 'numpy'. Please take care they do not conflict.
1171 INFO: Analyzing base_library.zip ...
6500 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
6502 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib'
7762 INFO: Caching module dependency graph...
7923 INFO: running Analysis Analysis-00.toc
7940 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Users\gauth\AppData\Local\Programs\Python\Python310\python.exe
8203 INFO: Analyzing C:\Users\gauth\Documents\project\project_debug3\project.py
9270 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
13260 INFO: Processing pre-find module path hook site from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
13262 INFO: site: retargeting to fake-dir 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\fake-modules'
22225 INFO: Processing pre-safe import module hook six.moves from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
32496 INFO: Processing module hooks...
32501 INFO: Loading module hook 'hook-certifi.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
32518 INFO: Loading module hook 'hook-Cryptodome.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
33041 INFO: Loading module hook 'hook-cryptography.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
34553 INFO: Loading module hook 'hook-cv2.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
34568 INFO: Loading module hook 'hook-google.api_core.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
34571 INFO: Loading module hook 'hook-googleapiclient.model.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
34647 WARNING: collect_data_files - skipping data collection for module 'googleapiclient.discovery' as it is not a package.
34648 INFO: Loading module hook 'hook-httplib2.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
34657 INFO: Loading module hook 'hook-lxml.etree.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
34658 INFO: Loading module hook 'hook-lxml.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
35621 INFO: Loading module hook 'hook-pycparser.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
35622 INFO: Loading module hook 'hook-selenium.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
35985 INFO: Loading module hook 'hook-unidecode.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
37029 INFO: Loading module hook 'hook-numpy.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\site-packages\\numpy\\_pyinstaller'...
37120 INFO: Import to be excluded not found: 'f2py'
37133 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37138 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37139 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37144 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37742 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37749 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37806 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37812 INFO: Loading module hook 'hook-numpy._pytesttester.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
37818 INFO: Loading module hook 'hook-pandas.io.formats.style.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
39392 WARNING: Hidden import "jinja2" not found!
39392 INFO: Loading module hook 'hook-pandas.plotting.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
39494 INFO: Loading module hook 'hook-pandas.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
41173 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
41180 INFO: Loading module hook 'hook-PIL.Image.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
42001 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
42008 INFO: Loading module hook 'hook-PIL.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
42034 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
42044 INFO: Loading module hook 'hook-pkg_resources.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
43000 INFO: Processing pre-safe import module hook win32com from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
43424 WARNING: Hidden import "pkg_resources.py2_warn" not found!
43425 WARNING: Hidden import "pkg_resources.markers" not found!
43431 INFO: Loading module hook 'hook-platform.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
43436 INFO: Loading module hook 'hook-PyQt5.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
43663 WARNING: Hidden import "sip" not found!
43663 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
43837 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
44120 INFO: Loading module hook 'hook-PyQt5.QtWidgets.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
44428 INFO: Loading module hook 'hook-pytz.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
44731 INFO: Loading module hook 'hook-setuptools.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
46244 INFO: Loading module hook 'hook-sqlite3.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
46833 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
46839 INFO: Loading module hook 'hook-win32ctypes.core.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
47606 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
47607 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
47610 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
47611 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
47785 INFO: checking Tree
47785 INFO: Building Tree because Tree-00.toc is non existent
47787 INFO: Building Tree Tree-00.toc
47929 INFO: checking Tree
47930 INFO: Building Tree because Tree-01.toc is non existent
47932 INFO: Building Tree Tree-01.toc
48034 INFO: checking Tree
48034 INFO: Building Tree because Tree-02.toc is non existent
48036 INFO: Building Tree Tree-02.toc
48043 INFO: Loading module hook 'hook-lxml.isoschematron.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
48053 INFO: Loading module hook 'hook-lxml.objectify.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
48054 INFO: Loading module hook 'hook-pythoncom.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
48631 INFO: Loading module hook 'hook-pywintypes.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
49207 INFO: Loading module hook 'hook-win32com.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
49737 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
49837 INFO: Looking for ctypes DLLs
50085 INFO: Analyzing run-time hooks ...
50106 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
50113 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
50120 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_win32api.py'
50121 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_win32comgenpy.py'
50123 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
50126 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
50130 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pyqt5.py'
50133 INFO: Including run-time hook 'C:\\Users\\gauth\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_subprocess.py'
50162 INFO: Looking for dynamic libraries
C:\Users\gauth\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py:156: UserWarning: The numpy.array_api submodule is still experimental. See NEP 47.
  __import__(package)
54020 INFO: Looking for eggs
54021 INFO: Using Python library C:\Users\gauth\AppData\Local\Programs\Python\Python310\python310.dll
54023 INFO: Found binding redirects:
[]
54041 INFO: Warnings written to C:\Users\gauth\Documents\project\project_debug3\build\project\warn-project.txt
54297 INFO: Graph cross-reference written to C:\Users\gauth\Documents\project\project_debug3\build\project\xref-project.html
54366 INFO: Appending 'datas' from .spec
54373 INFO: checking PYZ
54373 INFO: Building PYZ because PYZ-00.toc is non existent
54375 INFO: Building PYZ (ZlibArchive) C:\Users\gauth\Documents\project\project_debug3\build\project\PYZ-00.pyz
56527 INFO: Building PYZ (ZlibArchive) C:\Users\gauth\Documents\project\project_debug3\build\project\PYZ-00.pyz completed successfully.
56577 INFO: checking PKG
56578 INFO: Building PKG because PKG-00.toc is non existent
56580 INFO: Building PKG (CArchive) project.pkg
86615 INFO: Building PKG (CArchive) project.pkg completed successfully.
86640 INFO: Bootloader C:\Users\gauth\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
86640 INFO: checking EXE
86640 INFO: Building EXE because EXE-00.toc is non existent
86641 INFO: Building EXE from EXE-00.toc
86643 INFO: Copying bootloader EXE to C:\Users\gauth\Documents\project\project_debug3\dist\project.exe.notanexecutable
86648 INFO: Copying icon to EXE
86653 INFO: Copying icons from ['C:\\Users\\gauth\\Documents\\project\\project_debug3\\icon_project_256.ico']
86654 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
86654 INFO: Writing RT_ICON 1 resource with 14739 bytes
86657 INFO: Copying 0 resources to EXE
86657 INFO: Embedding manifest in EXE
86659 INFO: Updating manifest in C:\Users\gauth\Documents\project\project_debug3\dist\project.exe.notanexecutable
86660 INFO: Updating resource type 24 name 1 language 0
86663 INFO: Appending PKG archive to EXE
86763 INFO: Fixing EXE headers
87437 INFO: Building EXE from EXE-00.toc completed successfully.

Is there anyone who has any idea how to fix this issue?

dracenliu commented 2 years ago
115 INFO: PyInstaller: 5.2
115 INFO: Python: 3.10.5
179 INFO: Platform: Windows-10-10.0.22000-SP0
179 INFO: UPX is not available.
179 INFO: Extending PYTHONPATH with paths
['D:\\workspaces_py\\factorytools', 'D:\\workspaces_py\\factorytools']
19 WARNING: qt_material must be imported after PySide or PyQt!
965 INFO: checking Analysis
1162 INFO: Appending 'datas' from .spec
1179 INFO: checking PYZ
1296 INFO: checking PKG
1296 INFO: Building because toc changed
1296 INFO: Building PKG (CArchive) Tools.pkg
21271 INFO: Building PKG (CArchive) Tools.pkg completed successfully.
21271 INFO: Bootloader D:\Program Files\python\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
21271 INFO: checking EXE
21271 INFO: Building because toc changed
21271 INFO: Building EXE from EXE-00.toc
21287 INFO: Copying bootloader EXE to D:\workspaces_py\factorytools\dist\Tools.exe.notanexecutable
21400 INFO: Copying icon to EXE
21416 INFO: Copying icons from ['D:\\Program Files\\python\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
21416 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
21416 INFO: Writing RT_ICON 1 resource with 3752 bytes
21416 INFO: Writing RT_ICON 2 resource with 2216 bytes
21416 INFO: Writing RT_ICON 3 resource with 1384 bytes
21416 INFO: Writing RT_ICON 4 resource with 37019 bytes
21416 INFO: Writing RT_ICON 5 resource with 9640 bytes
21416 INFO: Writing RT_ICON 6 resource with 4264 bytes
21416 INFO: Writing RT_ICON 7 resource with 1128 bytes
21484 INFO: Copying 0 resources to EXE
21484 INFO: Embedding manifest in EXE
21484 INFO: Updating manifest in D:\workspaces_py\factorytools\dist\Tools.exe.notanexecutable
21484 INFO: Updating resource type 24 name 1 language 0
21560 INFO: Appending PKG archive to EXE
21702 INFO: Fixing EXE headers
22098 INFO: Building EXE from EXE-00.toc completed successfully.
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
    __cause__ = None
    __class__ = <class 'ImportError'>
    __context__ = None
    __delattr__ = <method-wrapper '__delattr__' of ImportError object>
    __dict__ = {}
    __dir__ = <built-in method __dir__ of ImportError object>
    __doc__ = "Import can't find module, or can't find name in module."
    __eq__ = <method-wrapper '__eq__' of ImportError object>
    __format__ = <built-in method __format__ of ImportError object>
    __ge__ = <method-wrapper '__ge__' of ImportError object>
    __getattribute__ = <method-wrapper '__getattribute__' of ImportError object>
    __gt__ = <method-wrapper '__gt__' of ImportError object>
    __hash__ = <method-wrapper '__hash__' of ImportError object>
    __init__ = <method-wrapper '__init__' of ImportError object>
    __init_subclass__ = <built-in method __init_subclass__ of type object>
    __le__ = <method-wrapper '__le__' of ImportError object>
    __lt__ = <method-wrapper '__lt__' of ImportError object>
    __ne__ = <method-wrapper '__ne__' of ImportError object>
    __new__ = <built-in method __new__ of type object>
    __reduce__ = <built-in method __reduce__ of ImportError object>
    __reduce_ex__ = <built-in method __reduce_ex__ of ImportError object>
    __repr__ = <method-wrapper '__repr__' of ImportError object>
    __setattr__ = <method-wrapper '__setattr__' of ImportError object>
    __setstate__ = <built-in method __setstate__ of ImportError object>
    __sizeof__ = <built-in method __sizeof__ of ImportError object>
    __str__ = <method-wrapper '__str__' of ImportError object>
    __subclasshook__ = <built-in method __subclasshook__ of type object>
    __suppress_context__ = False
    __traceback__ = <traceback object>
    args = ('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.',)
    msg = 'ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.'
    name = None
    path = None
    with_traceback = <built-in method with_traceback of ImportError object>

The above is a description of an error in a Python program.  Here is
the original traceback:

Traceback (most recent call last):
  File "ui\MainWindow.py", line 120, in onStartBtnClicked
  File "msg\func.py", line 39, in getFucClsByKey
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "ui\imagetest\imagetestWindow.py", line 15, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "ui\imagetest\adbsocket.py", line 5, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib\__init__.py", line 126, in import_module
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "cv2\__init__.py", line 76, 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.

I have the same problem! How to fix it?

asmorkalov commented 2 years ago

https://github.com/opencv/opencv-python/issues/689

MarioPonce2910 commented 2 years ago

Same here. I also had to revert to 4.5.5.64

Work for me ! Thx

thucungcuatoi commented 2 years ago

https://github.com/opencv/opencv-python/issues/680#issuecomment-1191427477

4.5.5.64 I have same this issue and try reinstall opencv-python 4.5.5.64! It's OK

samuller commented 2 years ago

@asenyaev You didn't show the result of running the executable? The exception doesn't happen during the pyInstaller creation step, but only when the resulting executable is run, e.g. ./dist/test (or ./dist/test/test when --onefile isn't used). I hope that's the difference.

@asmorkalov I just quickly tried the code change used in the MR fix for #689 (i.e. https://github.com/opencv/opencv/pull/22269/files), but it didn't make a difference to this issue on my local system. I might've made some mistake, but I suspect the iPython recursion issue might be different from this pyInstaller issue, and might not be fixed by that MR.

However, it looks like pyInstaller is aware of the issue, and they might have a fix on their side in an upcoming version: https://github.com/pyinstaller/pyinstaller/issues/6964#issuecomment-1193333632

Neizvestnyj commented 1 year ago

Same error. opencv-python==4.5.5.64 works

Alexandro1112 commented 1 year ago

commands

pip3 uninstall opencv-python==4.7.0.68

and

pip3 install -U opencv-python==4.5.3.56

successful installed OpenCV.

nanisahu commented 1 year ago

I use Windows 10, python 3.8, newest version of opencv-python. When I try to pack a exe with pyinstaller, I have the exact same problem. opencv-python==4.5.5.64 works fine.

I compared two version of init.py Maybe the key is in line 162: 4.5.5.64: native_module = importlib.import_module("cv2.cv2") 4.6.0.66: native_module = importlib.import_module("cv2")

It worked for me, after downgrading from 4.7.0.2 to 4.5.5.64. Thank you so much :)

Alexandro1112 commented 1 year ago

Version opencv dependencies between python version.

Alexandro1112 commented 1 year ago

For python 3.9 need opencv 4.5.5.64 version.

BrsBlinder commented 1 year ago

Got this error with opencv 4.8 for the following scenario: OpenCV built from sources with miniconda environment. Once the conda environment was ported to another machine, in python import cv2 started to fail with "ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions.." failure. The problem is a PYTHON_EXTENSIONS_PATHS absolute (absolute for the machine it was built on) path in a config-x.y.py file within generated python package. Changing the path to relative, fixes the problem.

johnmduval commented 1 year ago

Got this error with opencv 4.8 for the following scenario: OpenCV built from sources with miniconda environment. Once the conda environment was ported to another machine, in python import cv2 started to fail with "ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions.." failure. The problem is a PYTHON_EXTENSIONS_PATHS absolute (absolute for the machine it was built on) path in a config-x.y.py file within generated python package. Changing the path to relative, fixes the problem.

Hmm, I'm running into the same issue but I'm not totally clear what your workaround is. I built the opencv 4.8 source using cmake gui and put the output in "/opencv/build". I see there is a "config-3.11.py" file in the C:\Users\john\source\opencv\build\python_loader\cv2\ folder with an absolute path: "C:/Users/john/source/opencv/build/lib/python3/Release" (a folder which does not exist). Is this the file you were referring to? I tried changing that path to "../../lib/python3/Release" but it did not make a difference.

BrsBlinder commented 1 year ago

Change it to:

PYTHON_EXTENSIONS_PATHS = [ os.path.join(os.path.dirname(os.path.realpath(file)), 'python-3.11') ] + PYTHON_EXTENSIONS_PATHS

johnmduval commented 1 year ago

I think I'm missing something. The entire file consists of that one statement, I had to add "import os" to resolve "os is not defined" but I don't understand what the variable "file" references. On a hunch, I tried changing it to __file__ but I am still getting the error: recursion is detected during loading of "cv2"

I'm somewhat new to Python (but I am a SW dev), it feels like there is some context I'm not understanding.

Sloogs commented 1 year ago

I'm not sure if the cause of my issue is the same as others as I'm on a different OS/environment and stuff but hopefully this helps someone as I was able to resolve it.

Environment:

Here was the output I was getting while trying to run my program after bundling in PyInstaller.

Output

Process Process-1:
Traceback (most recent call last):
  File "multiprocessing/process.py", line 315, in _bootstrap
  File "multiprocessing/process.py", line 108, in run
  File "detectorprocess.py", line 350, in run_megadetector
    results = load_and_run_detector_batch(detector_filename, input_dir, progress=progress)
  File "detectorprocess.py", line 114, in load_and_run_detector_batch
    detector = load_detector(model_file)
  File "detection/run_detector.py", line 288, in load_detector
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "detection/pytorch_detector.py", line 17, in <module>
  File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
  File "general.py", line 31, in <module>
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/main.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/main.app/Contents/MacOS/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib/__init__.py", line 127, in import_module
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/main.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/main.app/Contents/MacOS/cv2/__init__.py", line 76, 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.

I had to try and find a way around this without downgrading OpenCV because I unfortunately was using modules that had very specific dependencies.

In order to reduce the number of variables that could be causing the issue, I created the following test script that only imports sys and cv2:

opencv-test.py

import sys
sys.OpenCV_LOADER_DEBUG = 1
print('pre-cv2')
import cv2
print(cv2.__file__)
print('post-cv2')

When running the script with python opencv-test.py, it finished successfully without any issues. I noticed that I got the following PYTHON_EXTENSIONS_PATHS, which thanks to some of the discussion in this issue thread, clued me in that it might be part of the issue.

OpenCV loader: PYTHON_EXTENSIONS_PATHS=['/Users/nick/anaconda3/envs/MegadetectorApp-m1/lib/python3.8/site-packages/cv2/python-3.8']

When I bundled it with PyInstaller, and tried to run it by invoking ./dist/opencv-test.app/Contents/MacOS/opencv-test, it produced the "recursion" error again. Before the exception got raised, it did print out some of the directories and indicated that it was looking for the following PYTHON_EXTENSIONS_PATHS:

OpenCV loader: PYTHON_EXTENSIONS_PATHS=['/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8']

The recursion error got triggered after printing the Relink everything from native cv2 module to cv2 package debug message of the OpenCV loader in ./cv2/__init__.py.

Output

pre-cv2
OpenCV loader: os.name="posix"  platform.system()="Darwin"
OpenCV loader: loading config: /Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/config.py
OpenCV loader: loading config: /Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/config-3.8.py
OpenCV loader: PYTHON_EXTENSIONS_PATHS=['/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8']
OpenCV loader: BINARIES_PATHS=['/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/../../lib']
Relink everything from native cv2 module to cv2 package
['/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/base_library.zip', '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8', '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/lib-dynload', '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS']
Traceback (most recent call last):
  File "opencv-test.py", line 5, in <module>
    import cv2
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib/__init__.py", line 127, in import_module
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 76, 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.
[94207] Failed to execute script 'opencv-test' due to unhandled exception: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
[94207] Traceback:
Traceback (most recent call last):
  File "opencv-test.py", line 5, in <module>
    import cv2
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib/__init__.py", line 127, in import_module
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 76, 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.

Thankfully I'm on a Mac, which lets devs actually dig into the .app file even if you're using --onefile. When I went into the bundled ./dist/opencv-test.app, I noticed that the folder ./dist/opencv-test.app/Contents/MacOS/cv2/python-3.8 was missing -- it seemed PyInstaller was not including it. (Recall: this was the PYTHON_EXTENSIONS_PATHS given above when OpenCV was being bundled by PyInstaller.)

When I looked inside the anaconda version in ~/anaconda3/envs/MegadetectorApp-m1/lib/python3.8/site-packages/cv2/python-3.8, there was a .so file named cv2.cpython-38-darwin.so. I copied that directly into the .app, into ./dist/opencv-test.app/Contents/MacOS/cv2/python-3.8, which resolved the "recursion" error. Why this is being raised as a "recursion" error isn't exactly clear to me, but then I got errors that some .dylibs were missing.

Output

Traceback (most recent call last):
  File "opencv-test.py", line 5, in <module>
    import cv2
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib/__init__.py", line 127, in import_module
ImportError: dlopen(/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/cv2.cpython-38-darwin.so, 0x0002): Library not loaded: @rpath/libopencv_hdf.406.dylib
  Referenced from: <E3FB7600-D402-328B-A124-2BB1227F85CB> /Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/cv2.cpython-38-darwin.so
  Reason: tried: '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/../../libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/../../libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/../../../../../libopencv_hdf.406.dylib' (no such file), '/usr/local/lib/libopencv_hdf.406.dylib' (no such file), '/usr/lib/libopencv_hdf.406.dylib' (no such file, not in dyld cache)
[94470] Failed to execute script 'opencv-test' due to unhandled exception: dlopen(/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/cv2.cpython-38-darwin.so, 0x0002): Library not loaded: @rpath/libopencv_hdf.406.dylib
  Referenced from: <E3FB7600-D402-328B-A124-2BB1227F85CB> /Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/cv2.cpython-38-darwin.so
  Reason: tried: '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/../../libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/../../libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/../../../../../libopencv_hdf.406.dylib' (no such file), '/usr/local/lib/libopencv_hdf.406.dylib' (no such file), '/usr/lib/libopencv_hdf.406.dylib' (no such file, not in dyld cache)
[94470] Traceback:
Traceback (most recent call last):
  File "opencv-test.py", line 5, in <module>
    import cv2
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "importlib/__init__.py", line 127, in import_module
ImportError: dlopen(/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/cv2.cpython-38-darwin.so, 0x0002): Library not loaded: @rpath/libopencv_hdf.406.dylib
  Referenced from: <E3FB7600-D402-328B-A124-2BB1227F85CB> /Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/cv2.cpython-38-darwin.so
  Reason: tried: '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/../../libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/cv2/python-3.8/../../libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/libopencv_hdf.406.dylib' (no such file), '/Users/nick/PycharmProjects/MegadetectorApp/dist/opencv-test.app/Contents/MacOS/../../../../../libopencv_hdf.406.dylib' (no such file), '/usr/local/lib/libopencv_hdf.406.dylib' (no such file), '/usr/lib/libopencv_hdf.406.dylib' (no such file, not in dyld cache)

This made me suspect that PyInstaller was not able to see all of the libraries that it needs to bundle without some help.

I got some inspiration from https://github.com/pyinstaller/pyinstaller/issues/6624 and managed to get this to work by adding the following the PyInstaller .spec file.

opencv-test.spec

# On my system, this would lead to e.g.:
# /Users/<my_name>/anaconda3/envs/<env_name>/lib/python3.8/site-packages/cv2
cv2_path = os.path.join(os.environ['CONDA_PREFIX'], 'lib', 'python3.8', 'site-packages', 'cv2')

a = Analysis(
...
    pathex=[os.path.join(cv2_path, 'python-3.8')],
    binaries=[(os.path.join(cv2_path, 'python-3.8', 'cv2.cpython-38-darwin.so'), './cv2/python-3.8')],
...
)

Of course on different systems you may need to change a few things, like python3.8 and python-3.8 to whatever version of Python you're using, change the cv2.cpython-38-darwin.so file to whatever one was included for your system, and to change the cv2_path to wherever your cv2 lives.

I'm hoping I didn't forget anything but that was what worked for me.

So I suspect that at least one of the causes of this issue are that static and dynamic library files are not getting included by PyInstaller in some environments. Perhaps that means some PyInstaller hooks for cv2 need to be updated. Also, I'm not sure I understand enough about how the OpenCV loader and PyInstaller interact but it would be worth investigating why missing libraries trigger a recursive loading issue.