Search code examples
pythonopencvpyinstallerubuntu-18.04nvidia-jetson

How to include OpenCV in pyinstaller when opencv is installed from source?


I have installed OpenCV 4.1 in Jetson Nano from source. It works perfect when i run my python3 code. After compiling python code using pyinstaller it throws ImportError.

ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

How do I compile python code using PyInstaller to make OpenCV included? Is there any other method to install OpenCV? I have tried pip3 install opencv-python but it does not find the matching distribution and if I install using sudo apt-get install python3-opencv it installs an older version. Any help wou.d be helpful.

I have also followed this thread but it does not work when OpenCV is compiled from source...


Solution

  • After lots of debugging, I found the following solution:
    Python 3.6
    OpenCV 4.1 (Compiled from source)
    pyinstaller 3.5

    1. Get the path of OpenCV

    import cv2
    print(cv2.__file__) # /usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.so
    

    2. Add this path while compiling through pyinstaller

    pyinstaller main.py -n myApp --paths="/usr/local/lib/python3.6/dist-packages/cv2/python-3.6"
    

    I hope this helps others also