Why does MATLAB Engine for Python crash when using a non system default version of Python on MAC?
3 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2015-2-26
编辑: MathWorks Support Team
2021-4-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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call MATLAB from Python 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!