Search code examples
pythonpyinstallerraspberry-pi3raspbianopenvino

OpenVino and PyInstaller on Raspberry PI 3B+


I tried to build a standalone executable with PyInstaller for Python 3.5 using OpenVino 2020.4.287.

PyInstaller assembled a file successfully but I received the next error after launch:

ImportError: No module named 'openvino'

I tried to include /opt/intel/openvino/deployment_tools/inference_engine/lib/armv7l/plugins.xml in data while building executable but it didn't help.

So the question is how to build a standalone executable in Raspbian with PyInstaller with OpenVino import?

Thanks.


Solution

  • Okay, the issue was resolved.

    Initial conditions:

    Raspbian Stretch with Python 3.5.

    Considerations:

    The last OpenVino supporting Python 3.5 is 2020.4.

    So, let’s start. We will create a test.py file with the next lines:

    import numpy as np
    import openvino.inference_engine.constants
    from openvino.inference_engine import IENetwork, IECore
    print("start")
    e = IECore()
    print("end")
    

    Now let's install OpenVino, Pyinstaller, create an executable, and run it:

    sudo pip3 install pyinstaller
    sudo mkdir -p /opt/intel/openvino
    wget https://storage.openvinotoolkit.org/repositories/openvino/packages/2020.4/l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz
    sudo tar -xf l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz --strip 1 -C /opt/intel/openvino
    rm l_openvino_toolkit_runtime_raspbian_p_2020.4.287.tgz
    sudo apt install cmake
    source /opt/intel/openvino/bin/setupvars.sh
    sh /opt/intel/openvino/install_dependencies/install_NCS_udev_rules.sh
    pyinstaller --onefile --clean --add-data="/opt/intel/openvino/deployment_tools/inference_engine/lib/armv7l/plugins.xml:." test.py
    dist/test
    

    "start" and "end" messages should be shown.

    The most important when you are using OpenVino 2020.4 is the next line:

    import openvino.inference_engine.constants
    

    In previous versions of OpenVino everything will work normally without this line. But in my specific case I’ve got the next error on OpenVino versions earlier 2020.4: openvino.inference_engine.ie_api.IECore' object has no attribute 'read_network That’s why I specified import for openvino.inference_engine.constants. Without this nothing works in OpenVino 2020.4.

    Thanks.