自定义 Python 删除带有 OpenVINO 初始化的解释器
Custom Python Remove Interpreter with OpenVINO initialization
我使用PyCharm连接到远程解释器(但我猜答案有点不相关):基本上,PyCharm通过SSH连接到远程Python解释器并执行远程机器上的代码。
我使用的远程解释器实际上是“调整过的”。这是一个名为 mypython
的文件,其中包含以下代码:
#!/bin/bash -l
export PATH="/home/ubuntu/.local/bin:/usr/local/cuda-11.1/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:${PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:${LD_LIBRARY_PATH}"
export PYTHONPATH="/home/ubuntu/VideoProcessingFramework/install/bin:${PYTHONPATH}"
export PATH="/home/ubuntu/FFmpeg/build_x64_release_shared/bin:${PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/VideoProcessingFramework/install/bin:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/FFmpeg/build_x64_release_shared/lib:${LD_LIBRARY_PATH}"
export PATH="/home/ubuntu/pytorch/build/bin:${PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/pytorch/build/lib:${LD_LIBRARY_PATH}"
# My attempt at having OpenVINO working on PyCharm remote interpreter
export PYTHONPATH="${PYTHONPATH}:/opt/intel/openvino_2021.1.110/python/python3.6:/opt/intel/openvino_2021.1.110/python/python3:/opt/intel/openvino_2021.1.110/deployment_tools/tools/post_training_optimization_toolkit:/opt/intel/openvino_2021.1.110/deployment_tools/open_model_zoo/tools/accuracy_checker:/opt/intel/openvino_2021.1.110/deployment_tools/model_optimizer:/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/python:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib/python3.6/site-packages:/usr/lib/python3/dist-packages"
export OpenCV_DIR="/opt/intel/openvino_2021.1.110/opencv/cmake"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/lib:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib:/opt/intel/openvino_2021.1.110/opencv/lib:/opt/intel/openvino_2021.1.110/deployment_tools/ngraph/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/hddl_unite/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/hddl/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/gna/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/mkltiny_lnx/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/tbb/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/lib/intel64"
export GST_SAMPLES_DIR="/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/samples"
export MODELS_PATH="/root/intel/dl_streamer/models"
export PKG_CONFIG_PATH="/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/lib/pkgconfig:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib/pkgconfig:"
export GSTREAMER_EXECUTABLES_DIR="/opt/intel/openvino_2021.1.110/data_processing/gstreamer/bin:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/bin/gstreamer-1.0"
export GST_PLUGIN_PATH="$GST_PLUGIN_PATH:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib/gstreamer-1.0"
export GST_PLUGIN_SCANNER="/opt/intel/openvino_2021.1.110/data_processing/gstreamer/bin/gstreamer-1.0/gst-plugin-scanner"
export GST_VAAPI_ALL_DRIVERS=1
/usr/bin/python3 "$@"
这允许我指定 Python 所需的一些环境变量。由于我在远程机器上安装了 OpenVINO,因此我需要将命令添加到 mypython
代码:source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
。但是,一旦我这样做,PyCharm 似乎拒绝使用我的 mypython
解释器(它只是卡住了)。
动机:
- 如果我通过 ssh 进入我的远程机器并且 运行
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
然后我可以从 python3 正确导入 cv2
- 我从 PyCharm 远程解释器得到错误:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2882, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-c8ec22b3e787>", line 1, in <module>
import cv2
ImportError: /opt/intel/openvino_2021.1.110/opencv/lib/libopencv_dnn.so.4.5: undefined symbol: _ZN15InferenceEngine10CNNNetworkC1ERKSt10shared_ptrIN6ngraph8FunctionEE
可能的解决方案:
- 使用 ssh 登录服务器
- 运行
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
- 运行
printenv
将所有变量包含到 mypython
源代码中。
我仍然想知道在 mypython
源代码中是否有 运行 source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
的方法。
编辑:在我的例子中从我的环境变量中删除这个问题解决了这个问题:
export LD_LIBRARY_PATH="/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:${LD_LIBRARY_PATH}"
不确定我是否有使用 cuda 编译的旧 OpenCV 版本。
我使用PyCharm连接到远程解释器(但我猜答案有点不相关):基本上,PyCharm通过SSH连接到远程Python解释器并执行远程机器上的代码。
我使用的远程解释器实际上是“调整过的”。这是一个名为 mypython
的文件,其中包含以下代码:
#!/bin/bash -l
export PATH="/home/ubuntu/.local/bin:/usr/local/cuda-11.1/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:${PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:${LD_LIBRARY_PATH}"
export PYTHONPATH="/home/ubuntu/VideoProcessingFramework/install/bin:${PYTHONPATH}"
export PATH="/home/ubuntu/FFmpeg/build_x64_release_shared/bin:${PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/VideoProcessingFramework/install/bin:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/FFmpeg/build_x64_release_shared/lib:${LD_LIBRARY_PATH}"
export PATH="/home/ubuntu/pytorch/build/bin:${PATH}"
export LD_LIBRARY_PATH="/home/ubuntu/pytorch/build/lib:${LD_LIBRARY_PATH}"
# My attempt at having OpenVINO working on PyCharm remote interpreter
export PYTHONPATH="${PYTHONPATH}:/opt/intel/openvino_2021.1.110/python/python3.6:/opt/intel/openvino_2021.1.110/python/python3:/opt/intel/openvino_2021.1.110/deployment_tools/tools/post_training_optimization_toolkit:/opt/intel/openvino_2021.1.110/deployment_tools/open_model_zoo/tools/accuracy_checker:/opt/intel/openvino_2021.1.110/deployment_tools/model_optimizer:/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/python:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib/python3.6/site-packages:/usr/lib/python3/dist-packages"
export OpenCV_DIR="/opt/intel/openvino_2021.1.110/opencv/cmake"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/lib:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib:/opt/intel/openvino_2021.1.110/opencv/lib:/opt/intel/openvino_2021.1.110/deployment_tools/ngraph/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/hddl_unite/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/hddl/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/gna/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/mkltiny_lnx/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/tbb/lib:/opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/lib/intel64"
export GST_SAMPLES_DIR="/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/samples"
export MODELS_PATH="/root/intel/dl_streamer/models"
export PKG_CONFIG_PATH="/opt/intel/openvino_2021.1.110/data_processing/dl_streamer/lib/pkgconfig:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib/pkgconfig:"
export GSTREAMER_EXECUTABLES_DIR="/opt/intel/openvino_2021.1.110/data_processing/gstreamer/bin:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/bin/gstreamer-1.0"
export GST_PLUGIN_PATH="$GST_PLUGIN_PATH:/opt/intel/openvino_2021.1.110/data_processing/gstreamer/lib/gstreamer-1.0"
export GST_PLUGIN_SCANNER="/opt/intel/openvino_2021.1.110/data_processing/gstreamer/bin/gstreamer-1.0/gst-plugin-scanner"
export GST_VAAPI_ALL_DRIVERS=1
/usr/bin/python3 "$@"
这允许我指定 Python 所需的一些环境变量。由于我在远程机器上安装了 OpenVINO,因此我需要将命令添加到 mypython
代码:source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
。但是,一旦我这样做,PyCharm 似乎拒绝使用我的 mypython
解释器(它只是卡住了)。
动机:
- 如果我通过 ssh 进入我的远程机器并且 运行
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
然后我可以从 python3 正确导入 cv2
- 我从 PyCharm 远程解释器得到错误:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 2882, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-c8ec22b3e787>", line 1, in <module>
import cv2
ImportError: /opt/intel/openvino_2021.1.110/opencv/lib/libopencv_dnn.so.4.5: undefined symbol: _ZN15InferenceEngine10CNNNetworkC1ERKSt10shared_ptrIN6ngraph8FunctionEE
可能的解决方案:
- 使用 ssh 登录服务器
- 运行
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
- 运行
printenv
将所有变量包含到mypython
源代码中。 我仍然想知道在mypython
源代码中是否有 运行source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
的方法。
编辑:在我的例子中从我的环境变量中删除这个问题解决了这个问题:
export LD_LIBRARY_PATH="/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:/home/ubuntu/.local/lib:/usr/local/cuda-11.1/lib64:${LD_LIBRARY_PATH}"
不确定我是否有使用 cuda 编译的旧 OpenCV 版本。