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 runnin
Short answer: there were two problems that needed to be fixed
$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.Long answer: complete installation instructions for using MATLAB Engine with Anaconda
cd "/usr/local/MATLAB/R2017a/extern/engines/python"
sudo python3.5 setup.py install --prefix="/your_path_to_anaconda3/envs/your_env"
. At this point you should be able to import matlab
and matlab.engine
from within the Python of your Anaconda environment, but, in my case, starting the engine gave the segmentation error.find /your_path_to_anaconda3/envs/your_env/ -name libpython*
. In my case this returned:
sudo ln -s /your_path_to_anaconda3/envs/your_env/lib/libpython3.5m.dylib /usr/lib
. Note that you can only have one link called libpython3.5m.dylib in /usr/lib. So if you have multiple Anaconda environments using the same version of Python, you only need to set up this link once to whichever one. Remember not to delete this environment though, as that would break the link for all other environments relying on it. source activate your_env
. Check within your Anaconda environment whether LD_LIBRARY_PATH contains any references to the Anaconda environment echo $LD_LIBRARY_PATH
. If so, ensure that it no longer does: export LD_LIBRARY_PATH=only_paths_you_do_want_to_keep_separated_by_a_colon
. This export action needs to be repeated whenever you activate your Anaconda environment, so you may want to look into more permanent means of setting it. However, in my case (apart from the fact I had been adding it myself in the hope this would improve things) the path was actually added by pygpu, so I ended up resetting LD_LIBRARY_PATH from my python script (so far without noticing ill effects).