-
Notifications
You must be signed in to change notification settings - Fork 896
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation. #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same here. I also had to revert to 4.5.5.64 |
Hi @mrjeckel, @SeungjunNah! I've tried to reproduce the issue on my Ubuntu 18.04 installing My reproducing steps:
Output
|
I also tried to do the same steps in a container with Ubuntu 16, and it also finished successfully. Output Ubuntu 16
|
It can be something wrong with a local environment on your side. Could you check which OpenCV Python packages were installed using
Multiple OpenCV Python packages can break your environment. Please, use only one package at a time. In addition, I would suggest to use |
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 |
I have the same problem python3 -u -m trace -c run.py
otherwise it works normally |
Same problem on Windows 11 with Python 3.10.2, numpy==1.23.1, pyinstaller==5.2 and opencv-python==4.6.0.66
With opencv-python==4.5.5.64 works like a charm. |
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:
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:
Is there anyone who has any idea how to fix this issue? |
I have the same problem! How to fix it? |
Work for me ! Thx |
|
@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. @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: pyinstaller/pyinstaller#6964 (comment) |
Same error. |
commands pip3 uninstall opencv-python==4.7.0.68 and pip3 install -U opencv-python==4.5.3.56 successful installed OpenCV. |
It worked for me, after downgrading from 4.7.0.2 to 4.5.5.64. Thank you so much :) |
Version opencv dependencies between python version. |
For python 3.9 need opencv 4.5.5.64 version. |
Got this error with opencv 4.8 for the following scenario: |
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. |
Change it to: PYTHON_EXTENSIONS_PATHS = [ |
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 I'm somewhat new to Python (but I am a SW dev), it feels like there is some context I'm not understanding. |
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 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 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 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 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 When I looked inside the anaconda version in 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 pyinstaller/pyinstaller#6624 and managed to get this to work by adding the following the PyInstaller 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 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 |
Seeing a similar issue to #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
The text was updated successfully, but these errors were encountered: