2

Matlab engine for python (r2016a) appears to be installed and working with python. I can do the following from a bash prompt:

$ python
Python 3.4.5 |Anaconda 4.3.1 (64-bit)| (default, Jul  2 2016, 17:47:47) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab.engine
>>> eng = matlab.engine.start_matlab()
>>> eng.abs(-1)
1
>>> exit()

Next I start Spyder (typing "spyder &" from the same bash prompt) and this is what I get trying the same thing from within Spyder:

Python 3.4.5 |Anaconda 4.3.1 (64-bit)| (default, Jul  2 2016, 17:47:47) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matlab.engine
Traceback (most recent call last):
  File "/home/XXX/anaconda3/envs/mr2/lib/python3.4/site-packages/matlab/engine/__init__.py", line 42, in <module>
    pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
  File "/home/XXX/anaconda3/envs/mr2/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'matlabengineforpython3_4'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/XXX/anaconda3/envs/mr2/lib/python3.4/site-packages/matlab/engine/__init__.py", line 58, in <module>
    pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
  File "/home/XXX/anaconda3/envs/mr2/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1715, in load_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
ImportError: /opt/local/matlab2016a/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64/libicuio.so.54: undefined symbol: _ZN6icu_5413UnicodeString9doReplaceEiiPKDsii

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/XXX/anaconda3/envs/mr2/lib/python3.4/site-packages/matlab/engine/__init__.py", line 61, in <module>
    'MathWorks Technical Support for assistance: %s' % e)
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: /opt/local/matlab2016a/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64/libicuio.so.54: undefined symbol: _ZN6icu_5413UnicodeString9doReplaceEiiPKDsii
>>> 

Using IPython instead of python gives similar results but with a less informative error. It's clear that Spyder can't find the module matlabengineforpython3_4 but I don't know where to go from there.

How can I get the MATLAB engine to work correctly from within spyder?

hbraunDSP
  • 57
  • 7
  • Did you set `LD_LIBRARY_PATH` to make `matlab.engine` work? – Carlos Cordoba Oct 27 '17 at 20:24
  • No, I didn't. I thought that would affect both the terminal and spyder the same, though. – hbraunDSP Oct 27 '17 at 20:45
  • I think there is a conflict between the ICU library that comes with Matlab and the one that comes with Anaconda. ICU is a dependency of Qt, the graphical toolkit upon which both Spyder and Matlab are built. Updating Anaconda to its latest version (with `conda update anaconda`) could fix this problem. – Carlos Cordoba Oct 28 '17 at 15:03

1 Answers1

2

This issue might be due to an incompatibility between the libstdc++ shipped with MATLAB and the libstdc++ shipped with the system that the spyder was linked against.

"CXXABI_1.3.9 not found" error message indicates that the libstdc++.so.6 library that is included with MATLAB is missing ABI versions the system needs to draw graphical content.

This is caused because the version of this particular library packaged with MATLAB is older than the versions that come with newer Linux operating systems, which causes compatibility issues.

You can try the following workarounds:

  1. Renaming the libstdc++.so.6 library file so that MATLAB cannot find it and is forced to use the system's version of the library. This file is located in matlabroot/sys/os/glnxa64 . Renaming it to libstdc++.so.6.old should suffice. (where "matlabroot" is root installation directory of MATLAB)

  2. Forcing MATLAB to load the system version by setting the $LD_PRELOAD environment variable to the newer version of libstdc++.

Also, since you are trying to call an external program from MATLAB, this may be a third party issue. But, you can try setting the library paths correctly in 'LD_LIBRARY_PATH' system variable.

find / -name "libstdc++.so*"

I found that calling matlab with the command LD_PRELOAD=/usr/lib64/libstdc++.so.6 matlab -desktop seems to solve the issue

in order to avoid having to type this command every time I also assigned an alias on my .bashrc file alias matlab="LD_PRELOAD=/usr/lib64/libstdc++.so.6 /usr/local/bin/matlab -desktop"

https://cn.mathworks.com/matlabcentral/answers/329796-issue-with-libstdc-so-6

khaverim
  • 3,386
  • 5
  • 36
  • 46
ansi
  • 21
  • 2