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

8 ビュー (過去 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 日
編集済み: 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 Center および File ExchangeCall 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