pythonmatlabpython-3.xanacondamatlab-engine

Starting Matlab engine in anaconda virtual environment returns 'Segmentation fault (core dumped)'


I've installed the official MATLAB Engine by following the instructions from the answer to Anaconda install Matlab Engine on Linux to an Anaconda virtual environment running Python3.5. I can now import matlab and matlab.engine without receiving errors. However, when I try: matlab.engine.start_matlab(), I get 'Segmentation fault (core dumped)'

I've tried setting LD_LIBRARY_PATH from within the conda environment (in case that is even relevant): export LD_LIBRARY_PATH=/System/Library/Frameworks/Python.framework/Versions/Current/lib:$LD_LIBRARY_PATH, but to no avail. The path doesn't exist either as far as I'm aware, so I've also tried export DYLD_LIBRARY_PATH=path_to_anaconda3/envs/myEnv/lib:$LD_LIBRARY_PATH

So how can I start the matlab engine/call Matlab scripts from Python from within a Anaconda virtual environment?

I'm on Ubuntu, by the way


Solution

  • Short answer: there were two problems that needed to be fixed

    1. $LD_LIBRARY_PATH should not contain a path to the Anaconda installation. Adding such a path is discouraged according to the conda documentation: https://conda.io/docs/building/shared-libraries.html, but some packages may do so anyways, causing the segmentation error.
    2. A symbolic link is needed from a libpythonXXX.dylib file of the right version to /usr/lib/, so that MATLAB can find the right Python

    Long answer: complete installation instructions for using MATLAB Engine with Anaconda