Why does MATLAB Engine for Python crash when using a non system default version of Python on MAC?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 26 de Feb. de 2015
Editada: MathWorks Support Team
el 30 de Abr. de 2021
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
Respuesta aceptada
MathWorks Support Team
el 30 de Abr. de 2021
Editada: MathWorks Support Team
el 30 de Abr. de 2021
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Call MATLAB from Python en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!