-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Error "ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation." with Pyinstaller #7128
Description
Environment:
Mac M1 - macOS Monterey
PyInstaller: 5.4.1
Python: 3.8.10
opencv-contrib-python==4.6.0.66
opencv-python==4.6.0.66
Script
pyinstaller -n "App" --windowed App.py
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 "App.py", line 6, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
File "main.py", line 28, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
File "image_manager.py", line 6, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
File "workers/image_worker.py", line 6, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 499, in exec_module
File "modules/apply_effects.py", line 3, in <module>
File "/Users/Josh/Desktop/Work-Stuff/App-Offline/dist/App.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/Users/Josh/Desktop/Work-Stuff/App-Offline/dist/App.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
applySysPathWorkaround = True
File "/Users/Josh/Desktop/Work-Stuff/App-Offline/dist/App.app/Contents/MacOS/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/Users/Josh/Desktop/Work-Stuff/App-Offline/dist/App.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 fixed this by replacing the cv2 folder in Contents/Resources with the cv2 folder in site-packages.
Notes:
I ran the diff -r .venv/lib/python3.8/site-packages/cv2 dist/App.app/Contents/Resources/cv2 >> cv2-diff.txt to see the difference between the two directories, and this was the relevant output.
Only in .venv/lib/python3.8/site-packages/cv2: .dylibs
Only in .venv/lib/python3.8/site-packages/cv2: cv2.abi3.so
Update:
I don't need to copy the whole cv2 folder from site-packages, I only need to copy the .dylibs directory and the cv2.abi3.so file from site-packages/cv2