如何使用 Python* API 包装器从源代码构建面向 Linux* 的开源OpenVINO™工具套件

文档

安装与设置

000057448

2022 年 12 月 20 日

要将 Python* 与 Linux* 版开源 OpenVINO™工具套 件一同使用,您必须安装 Python* 3.5 或更高版本,然后再在 CMake 命令行中指定正确的 Python 版本来构建该工具套件。

如果您未明确指定 Python 版本,CMake 会选择系统级 Python 版本(2.7),而且您的 Python 脚本将不起作用。

注意

以下说明假定您已安装了 Python*。

  1. 建立 来源。

    有关更多详细步骤,请参阅“楼宇为 Linux* ”的说明

    $ git clone https://github.com/openvinotoolkit/openvino.git
    $ cd openvino
    $ git submodule update --init --recursive
    $ chmod +x install_build_dependencies.sh
    $ ./install_build_dependencies.sh
    $ mkdir build && cd build

    $ python3 -m pip install -r ../src/bindings/python/src/compatibility/openvino/requirements-dev.txt

     

    注意

    在下面的 CMake 命令行中,用您的 Python* 版本替换 3.8。Python 的位置和版本取决于架构和操作系统。

     

    $ cmake -DCMAKE_BUILD_TYPE=Release \
    -DENABLE_PYTHON=ON \
    -DPYTHON_EXECUTABLE=`which python3.8` \
    -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.8.so \
    -DPYTHON_INCLUDE_DIR=/usr/include/python3.8 ..
    $ make --jobs=$(nproc --all)

     

  2. 出口 环境变量。

    构建过程完成后, 导出 环境变量:

    $ export PYTHONPATH=$PYTHONPATH:/~/openvino/bin/intel64/Release/python_api/python3.8/
    $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/openvino/bin/intel64/Release/

     

  3. 测试 构建。

    运行 以下脚本以导入内核,检查您是否正确构建了 Python* 包装器:

    $ python3.8
    >>> from openvino.runtime import Core

     

如果可以成功导入内核,您已经使用 Python 包装器正确构建了OpenVINO™工具套件。