Why does MATLAB Engine for Python crash when using a non system default version of Python on MAC?

3 次查看(过去 30 天)
I have downloaded the latest Python 2.7.x version from https://www.python.org/ for Mac OS X 10.10 and installed it through its default installer in the default location. I then Installed MATLAB Engine for Python in this Python version; this completed without errors. When I try to use the Engine however, Python crashes on the line:
import matlab.engine
The error message which is displayed is:
Segmentation fault: 11

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2021-4-30
MATLAB Engine for Python depends on a shared library matlabengineforpython2_7.so which in turn depends on libpython2.7.dylib. This libpython2.7.dylib is loaded as run-path-relative library (@rpath). In most Mac OS X setups this will mean that /usr/lib/libpython2.7.dylib will be used at runtime. This particular library is the system default library however, it is not updated or changed by the installers downloaded from https://www.python.org/ . Meaning that there will be a mismatch between your Python interpreter version and the libpython2.7.dylib loaded by MATLAB Engine for Python. This then leads to a segmentation fault.
To resolve this issue we need to make sure that MATLAB Engine for Python can find the correct version of libpython2.7.dylib. To accomplish this add the |lib| directory of the correct Python version to the DYLD_LIBRARY_PATH. Assuming that Python was installed in its default you should for example be able to run the following in a Terminal to start Python with the correct environment:
export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/lib:$DYLD_LIBRARY_PATH
python

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call MATLAB from Python 的更多信息

标签

尚未输入任何标签。

产品


版本

R2014b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by