[英]Custom Python Remove Interpreter with OpenVINO initialization
I use PyCharm to connect to a remote interpreter (but I guess the answer is somewhat unrelated): basically, PyCharm connects to a remote Python interpreter through SSH and execute the code on a remote machine.我使用 PyCharm 连接到远程解释器(但我想答案有些无关):基本上,PyCharm 通过 SSH 连接到远程 Python 解释器并在远程机器上执行代码。
The remote interpreter that I used is actually "tweaked".我使用的远程解释器实际上是“调整”的。 It is a file called
mypython
that contains the following code:它是一个名为
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 "$@"
This allows me to specify some environment variables required by Python.这允许我指定 Python 所需的一些环境变量。 Since I install OpenVINO on the remote machine, I would need to add to
mypython
code the command: source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
.由于我在远程机器上安装了 OpenVINO,我需要将命令添加到
mypython
代码中: source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
。 However, once I do this, it seems that PyCharm refuses to use my mypython
interpreter (it just gets stuck).但是,一旦我这样做,PyCharm 似乎拒绝使用我的
mypython
解释器(它只是卡住了)。
Motivation:动机:
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
I can then import cv2 correctly from python3source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
我可以从 python3 正确导入 cv2Traceback (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
Possible solution:可能的解决方案:
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
printenv
Include all the variables into the mypython
source code.printenv
所有变量包含到mypython
源代码中。 I would still like to know if there is a way to run source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
within mypython
source code.mypython
源代码中运行source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
。 EDIT: in my case removing this from my environment variables fixed the issue:编辑:在我的情况下,从我的环境变量中删除它解决了这个问题:
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}"
Not sure if I had an old OpenCV version compiled with cuda.不确定我是否有使用 cuda 编译的旧 OpenCV 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.