2

I used the Matlab Engine for Python a lot last fall, without any trouble. I just tried to reuse my old code today and I get the following error:

>>> import matlab.engine
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/matlab/engine/__init__.py", line 59, in <module>
    raise EnvironmentError('The installation of MATLAB Engine for Python is '
EnvironmentError: The installation of MATLAB Engine for Python is corrupted.  Please reinstall it or contact MathWorks Technical Support for assistance.

I am on MacOSX 10.11 (El Capitan), using Python 2.7 and Matlab 2015a. I reinstalled the Matlab Engine twice already, but no difference, I still get the same error.

Looking at the ini.py file, it seems that the line that fails is the following, yielding the error copied here:

>>> pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: dlopen(/Applications/MATLAB_R2015a.app/extern/engines/python/dist/matlab/engine/maci64/matlabengineforpython2_7.so, 2): Library not loaded: @rpath/libpython2.7.dylib
  Referenced from: /Applications/MATLAB_R2015a.app/extern/engines/python/dist/matlab/engine/maci64/matlabengineforpython2_7.so
  Reason: image not found

I have read a similar question where the answers pointed towards an issue with the libpython2.7.dylib HERE but I'm not sure I understand the solution. I can see the libpython2.7.dylib file in my /usr/lib/ folder.

Cynthia GS
  • 522
  • 4
  • 20
  • Did you happen to upgrade your OS between the time you last used it up until this point? – rayryeng May 10 '16 at 17:52
  • I actually don't think so, since El Cap came out in September 2015. So I'm pretty sure I successfully used the matlab engine after upgrading. – Cynthia GS May 10 '16 at 17:58
  • It's looking like the re-install didn't actual replace the old files. Can I just get rid of the entire `matlab` folder in my `site-packages` folder to get a clean install? – Cynthia GS May 10 '16 at 18:24
  • That's interesting. Yes, you can remove that directory from your `site-packages` and try it again. – rayryeng May 10 '16 at 18:25
  • Hmmmm... weird, I removed the folder and reinstalled the engine, and I still get the exact same error message. – Cynthia GS May 10 '16 at 18:29
  • See edits: I think I identified the issue, which seems to be indeed coming from the libpython2.7.dylib file... – Cynthia GS May 10 '16 at 19:26
  • OK, this may be a stretch but do you have perhaps multiple versions of Python installed on your machine? This can happen when one distribution of Python has certain packages installed that the other doesn't. – rayryeng May 10 '16 at 19:28
  • I think I only have one version of 2.7...? I do see a few old versions as well. – Cynthia GS May 10 '16 at 19:55

1 Answers1

0

Based on THIS LINK, it seems like a possible issue is that MacOSX 10.11 requires Matlab 2015b or higher. However, Matlab 2015a works fine on my computer right now, so I'm not sure why the Engine wouldn't.

MacOSX requirements for Matlab Engine

Cynthia GS
  • 522
  • 4
  • 20