jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.79k stars 5k forks source link

matlab.engine throwing error message in jupyter notebook but not in terminal #2325

Open alexanderwhatley opened 7 years ago

alexanderwhatley commented 7 years ago

Platform: Ubuntu 16.10

I am trying to use the matlab-python interface in the jupyter notebook (https://www.mathworks.com/help/matlab/matlab-engine-for-python.html). The interface works fine in the terminal, but not in the notebook. It seems like the notebook does not have the same access to C++ compilers that the command line python does. See here where someone else also had this problem: http://stackoverflow.com/questions/36076395/import-of-matlab-engine-works-in-ipython-but-not-in-jupyter The solution that they had, which was to set LD_LIBRARY_PATH, did not work for me.

When I try to run import matlab.engine in the notebook, I get the following error message, which indicates that it was unable to find the necessary C++ compiler:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/home/alexander/anaconda3/lib/python3.5/site-packages/matlab/engine/__init__.py in <module>()
     41 try:
---> 42     pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
     43 except:

/home/alexander/anaconda3/lib/python3.5/importlib/__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _gcd_import(name, package, level)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _find_and_load(name, import_)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _load_unlocked(spec)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in module_from_spec(spec)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap_external.py in create_module(self, spec)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: /home/alexander/anaconda3/lib/python3.5/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/MATLAB/R2017a/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64/libmx.so)

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
/home/alexander/anaconda3/lib/python3.5/site-packages/matlab/engine/__init__.py in <module>()
     57                 os.environ[_envs[_arch]] = _bin_dir
---> 58         pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
     59     except Exception as e:

/home/alexander/anaconda3/lib/python3.5/importlib/__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _gcd_import(name, package, level)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _find_and_load(name, import_)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _load_unlocked(spec)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in module_from_spec(spec)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap_external.py in create_module(self, spec)

/home/alexander/anaconda3/lib/python3.5/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: /home/alexander/anaconda3/lib/python3.5/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/MATLAB/R2017a/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64/libmx.so)

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-2-7ec811bb5400> in <module>()
----> 1 import matlab.engine

/home/alexander/anaconda3/lib/python3.5/site-packages/matlab/engine/__init__.py in <module>()
     59     except Exception as e:
     60         raise EnvironmentError('Please reinstall MATLAB Engine for Python or contact '
---> 61                                'MathWorks Technical Support for assistance: %s' % e)
     62 
     63 

OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: /home/alexander/anaconda3/lib/python3.5/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/MATLAB/R2017a/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64/libmx.so)
gnestor commented 7 years ago

@Carreau Any thoughts?

Carreau commented 7 years ago

The solution that they had, which was to set LD_LIBRARY_PATH, did not work for me.

How did you set this ? If you did it before running the notebook it might not have any effect, try using things like a2km to set environment variable in the kernelspec.

I had similar issues with RPy2, and that solved it for me.

sharbatc commented 7 years ago

I have the same problem, I checked my environment variables by printing out %env in the cell and it did print out the correct path assigned to it via .bashrc. However, the error is still of the form -

ImportError: /home/sharbat/anaconda3/lib/python3.5/sitepackages/zmq/backend/cython/../../../../.././libstdc++.so.6: version 'CXXABI_1.3.8' not found (required by /usr/local/MATLAB/R2016b/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64/libmx.so)

which is the same as the one above. Anyone else got a solution?

EDIT : I checked and found that there is no such thing as a sitepackages and it is in fact at the following directory that I actually do have CXXABI_1.3.8 /home/sharbat/anaconda3/lib/python3.5/sitepackages/zmq/backend/cython/../../../../.././libstdc++.so.6

So I guess have to get jupyter notebook to not look where it is looking... does changing LD_LIBRARY_PATH do that?

EDIT : So, I changed the LD_LIBRARY_PATH to make it point to where I got the CXXABI_1.3.8 via scanelf -l -s CXXABI_1.3.8 | grep CXXABI_1.3.8 which returned ET_DYN CXXABI_1.3.8 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.23

It worked.

JumperWang commented 6 years ago

if you have code: import sys import matlab.engine

The code "import matlab.engine" must be put at the first line, or you'll get the following error EnvironmentError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: /opt/MATLAB/R2016b/extern/engines/python/dist/matlab/engine/glnxa64/../../../../../../../bin/glnxa64/libssl.so.1.0.0: undefined symbol: EVP_idea_cbc