Cv2 import error when I run executable file built by pyinstaller

Hi, I face an issue with import cv2 when I run executable file built by pyinstaller.

I built executable file using pyinstaller inside docker container.
when I run the executable file, below error occurs.

‘’'sh
[’/tmp/_MEI4rglmg/base_library.zip’, ‘/tmp/_MEI4rglmg/cv2/python-3.6’, ‘/tmp/_MEI4rglmg/lib-dynload’, ‘/tmp/_MEI4rglmg’]
Traceback (most recent call last):

  • File “show.py”, line 1, in *
  • File “PyInstaller/loader/pyimod03_importers.py”, line 495, in exec_module*
  • File “cv2/init.py”, line 89, in *
  • File “cv2/init.py”, line 79, in bootstrap*
  • File “PyInstaller/loader/pyimod03_importers.py”, line 495, in exec_module*
  • File “cv2/init.py”, line 89, in *
  • File “cv2/init.py”, line 23, in bootstrap*
    ImportError: ERROR: recursion is detected during loading of “cv2” binary extensions. Check OpenCV installation.
    [1245] Failed to execute script ‘show’ due to unhandled exception!
    ‘’’

Below is my python script file to build.
import cv2

cam = cv2.VideoCapture(0)
cam.set(3, 640)
cam.set(4, 480)

for i in range(2000):
ret, img = cam.read()
cv2.imshow(‘test’, img)
if cv2.waitKey(1) == 27:
break

My environment information:
hardware: jetson nano
image: nvcr.io/nvidia/l4t-ml:r32.5.0-py3
command to run docker :
xhost + && docker run -it --rm --runtime nvidia --network host --privileged -e DISPLAY=$DISPLAY -v /tmp/argus_socket:/tmp/argus_socket -v /tmp/.X11-unix:/tmp/.X11-unix --device /dev/video0 nvcr.io/nvidia/l4t-ml:r32.5.0-py3

additional library installed:
apt install libcanberra-gtk-module libcanberra-gtk3-module
pyinstaller version: 4.8
issued pyinstaller command: pyinstaller -w -F show.py

I need to build one file for my application which import cv2.
Please help me.

Hi,

This is a known issue due to the inconsistent version between JetPack and PyInstaller.
Please check the wiki below for the workaround:
https://elinux.org/Jetson/L4T/TRT_Customized_Example#PyInstaller_with_OpenCV

Thanks.

Thanks for the quick reply.
It was perfect solution for me.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.