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.

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

  • File “”, line 1, in *
  • File “PyInstaller/loader/”, line 495, in exec_module*
  • File “cv2/”, line 89, in *
  • File “cv2/”, line 79, in bootstrap*
  • File “PyInstaller/loader/”, line 495, in exec_module*
  • File “cv2/”, line 89, in *
  • File “cv2/”, 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 =
cv2.imshow(‘test’, img)
if cv2.waitKey(1) == 27:

My environment information:
hardware: jetson nano
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

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

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


This is a known issue due to the inconsistent version between JetPack and PyInstaller.
Please check the wiki below for the workaround:


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.