opencv-python: ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

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!

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 5
  • Comments: 23 (3 by maintainers)

Most upvoted comments

Same here. I also had to revert to 4.5.5.64

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.

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”)

For python 3.9 need opencv 4.5.5.64 version.

Same here. I also had to revert to 4.5.5.64

Work for me ! Thx

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:

  • Mac OS (M2 Mac)
  • Python 3.8 with Anaconda
  • conda==23.7.2
  • opencv==4.6.0
  • opencv-python==4.8.0.74
  • pyinstaller==5.6.2
  • pyinstaller-hooks-contrib==2022.14

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.

Same error. opencv-python==4.5.5.64 works

@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

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 deactivated my Antivirus. It didn’t work

I think I tried it all:

  • I installed the previous version of OpenCV:

    pip install opencv-python==4.5.3.56

It didn’t work

  • I installed the latest version:

    pip install --upgrade opencv-python pip install --upgrade pyinstaller

It didn’t work

  • I tried to force the reinstallation:

    pip3 install opencv-python --upgrade --force-reinstall

It didn’t work

  • I added the path of cv2:

    pyinstaller --onefile -F --uac-admin --icon=“icon_PhoneBot_256.ico” --clean --noconsole --collect-data pyshadow --paths=“C:\Users\gauth\AppData\Local\Programs\Python\Python310\Lib\site-packages\cv2” Project.py

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?

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