You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Nevermind, I've reproduced the problem, which is applicable only to .app bundles.
What happens is that we move the collected cv2 .py files from Contents/MacOS/cv2 to Contents/Resources/cv2 and symlink them back. But we don't do the same with the extension, and therefore the cv2 loader code fails to set the correct path to the extension (because it resolves the actual paths to .py files). Adding cv2 as an exemption similar to what we already do for PyQt/PySide directories (here) should also fix the problem - although god knows what notarization has to say about it...
Hey @rokm, I did as you said and on my local version of PyInstaller edited the osx.py and added cv2 to the set of exceptions as it was done (here), and it worked. Should I create a PR?
I think instead of exempting cv2 from relocation, we will need to exempt all .py files, because this will be a general problem with packages where we collect sources (perhaps moreso packages where we collect only sources, although that's only cv2 at the moment). I'll create a PR once I do some testing.
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:
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.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
The text was updated successfully, but these errors were encountered: