Issue with Python interface to TensorFlow and other third-party libraries in Mac and Linux
조회 수: 4 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2021년 1월 4일
답변: MathWorks Support Team
2021년 1월 5일
When I try to run TensorFlow (2.3) commands from MATLAB in out-of-process execution mode with a Linux or Mac OS, the process gets terminated.
Using TensorFlow 2.2, 2.1, or 2.0, I see a different error ("Unable to resolve the name ____") but the process is not terminated. Instead, the following is displayed at the terminal where MATLAB was launched:
[libprotobuf FATAL] This program requires version 3.8.0 of the Protocol Buffer runtime library, but the
installed version is 3.6.1. Please update your library. If you compiled the program yourself, make
sure that your headers are from the same version of Protocol Buffers as your link-time library.
(Version verification failed in "bazel-out/k8-py2-
opt/bin/tensorflow/core/framework/tensor_shape.pb.cc".)
채택된 답변
MathWorks Support Team
2021년 1월 4일
Python packages, like TensorFlow, often have dependencies on a number of third party libraries with specific version requirements. These may cause issues when MATLAB ships with the same libraries, but with different version requirements. Some of these conflicts may be avoided by running Python Interface in a separate process, but some conflicts may persist. One such conflict often occurs with the Protocol Buffer runtime library ('protobuf'), which is used by both TensorFlow and MATLAB, but with different versions. Other common examples include 'libexpat' and 'libcrypto'.
One workaround for this issue is to force TensorFlow to load the symbols from its own version of 'protobuf' instead of the version shipped with MATLAB. Taking the example of TensorFlow and 'protobuf', the code below demonstrates how to set the 'dlopen' flags and force TensorFlow to load its own version of 'protobuf'.
>> pyenv('Version', '<path to Python exectuable>', 'ExecutionMode', 'OutOfProcess');
>> RTLD_NOW=2;
>> RTLD_DEEPBIND=8;
>> flag=bitor(RTLD_NOW, RTLD_DEEPBIND);
>> py.sys.setdlopenflags(int32(flag));
>> c = py.tensorflow.constant(1);
The above example can be adapted for other packages where similar third-party library conflicts may be occurring.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!