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.
The remote interpreter that I used is actually “tweaked”. It is a file called mypython
that contains the following code:
#!/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. 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
. However, once I do this, it seems that PyCharm refuses to use my mypython
interpreter (it just gets stuck).
Motivation:
- If I ssh into my remote machine and run
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
I can then import cv2 correctly from python3 - From the PyCharm remote interpreter instead I get the error:
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
Advertisement
Answer
Possible solution:
- log into the server using ssh
- run
source /opt/intel/openvino_2021.1.110/bin/setupvars.sh
- run
printenv
Include all the variables into themypython
source code. I would still like to know if there is a way to runsource /opt/intel/openvino_2021.1.110/bin/setupvars.sh
withinmypython
source code.
EDIT: in my caseremoving 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.