syntax-highlighter

Friday, July 8, 2011

Installing mlabwrap on OS-X and Linux

Mlabwrap is an excellent Python wrapper for Matlab, allowing you to use Matlab functionality from within Python scripts. I recently tried to install it on OS-X (10.6) and Linux (11.4). I ran into minor issues with both OS'.

The first is that the setup.py that ships with version 1.1 of mlabwrap has a minor compile error related to the definition of a datatype. In my case this was fixed by changing:

# setup.py line 13
MATLAB_VERSION = None

to:
MATLAB_VERSION = 7.3

which tells mlabwrap to look for Matlab versions 7.3 and on. I made this change on both OS-X and Linux.

The second issue was with OS-X only, and relates to how mlabwrap references the Matlab shared libraries. Although mlabwrap builds successfully, import errors related to "@loader_path/libeng.dylib" and "@loader_path/libmx.dylib" occur.

I fixed this using the "install_name_tool" command to modify the mlabrawmodule.so library from mlabwrap so that it uses the absolute paths to these shared libraries:

The commands are:
sudo install_name_tool -change "@loader_path/libmx.dylib" "/Applications/Matlab_R2011a_Student/bin/maci64/libmx.dylib" mlabrawmodule.so


sudo install_name_tool -change "@loader_path/libeng.dylib" "/Applications/Matlab_R2011a_Student/bin/maci64/libeng.dylib" mlabrawmodule.so

Note that these commands assumes you are in the site-packages directory of your Python installation (or wherever you have install mlabwrap). You will also need to change the change the "/Matlab_R2011a_Student" portion of the paths to suit your Matlab installation.