2

Task: Call a function from Matlab 2013b using Python 3.x on Windows 7 (all x64).

Question: Is there a Python package that allows me to do that?

I already tried:

  • mlabwrap
  • python-matlab-bridge
  • pymatlab

but none of these work with the configuration given above.

Any information about a working configuration using Python 3.x is appreciated.

If you need more detailed information, please let me know.


Update: I am currently trying to get this working using Matlab2011b and Pyhton 2.7 as these seem to be the most used Versions. For now i am stuck at the following:

python-matlab-bridge I can import the module without problems but as soon as is start a Session a Matlab Command Window pops up and nothing else happens. The Python Window shows:

Starting MATLAB on ZMQ socket tcp://127.0.0.1:55555
Send 'exit' command to kill the server
............................................................Matlab session timed
 out after 60 seconds
MATLAB failed to start
Press any key to continue . . .

This happens every single time and no error is given.

mlabwrap I tried to install mlabwrap using this guide. On typing 'python setup.py install' a Matlab Command Window pops up and again nothing happens. If i close the Command Window the Python output shows:

WINDOWS SPECIFIC ISSUE? Unable to remove c:\users\martin\appdata\local\temp\tmp1
y2kdk; please delete it manually
[Error 32] Der Prozess kann nicht auf die Datei zugreifen, da sie von einem ande
ren Prozess verwendet wird: 'c:\\users\\martin\\appdata\\local\\temp\\tmp1y2kdk'


INSTALL ABORT: 'matlab -nodesktop -nosplash -wait -r "fid = fopen(\'c:\\users\\m
artin\\appdata\\local\\temp\\tmp1y2kdk\', \'wt\');fprintf(fid, \'%s%c%s%c%s%c\',
 version, 10, matlabroot, 10, computer, 10);fclose(fid); quit"' RETURNED ERROR C
ODE -805306369
PLEASE MAKE SURE matlab IS IN YOUR PATH!

My %Path% looks like this (only the important parts ;):

D:\MATLAB\R2011b\bin;C:\Program Files\ZeroMQ 4.0.4\lib;D:\Python27;D:\Python27\scripts;D:\MATLAB\R2011b\runtime\win64;D:\MATLAB\R2011b\extern\lib\win64\microsoft;D:\MATLAB\R2011b\bin\win64

Any help to get any connection between Matlab and Python on Windows is appreciated! I really can´t see why none of this is working...


Update2: I can install mlabwrap now but i can´t start it. When i try to import mlabwrap a Matlab Command Window opens up and closes after a minute. The Python output is:

>>> import mlabwrap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python27\lib\site-packages\mlabwrap.py", line 645, in <module>
    mlab = MlabWrap()
  File "D:\Python27\lib\site-packages\mlabwrap.py", line 405, in __init__
    self._session = mlabraw.open(os.getenv("MLABRAW_CMD_STR", ""))
mlabraw.error: Unable to start MATLAB(TM) engine

I double checked that the engdemo from Matlab is working.

Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46
  • 2
    As a last resort, MATLAB has a [COM Automation Server](http://www.mathworks.com/help/matlab/call-matlab-com-automation-server.html) that you can use with [`win32com`](https://pypi.python.org/pypi/pywin32), e.g. `m = win32com.client.Dispatch("Matlab.Application"); m.Execute('...'); m.Quit()`. – Eryk Sun Apr 01 '14 at 10:57
  • @eryksun Thanks! I will take a look at that. I would prefer a package like mlabwrap which is much eaier tu use. But as a last resort this could work. – Mailerdaimon Apr 01 '14 at 11:15
  • 1
    What are the exact problems/errors that you get with the mentioned packages? – Florian Brucker Apr 01 '14 at 11:47
  • First Probleme is that most packages are not Python 3.3 ready. I tried to convert some of them. As i am currently trying out a lot i can´t give you an exact error message (yet). Most of the time i stuck at a point where a dll can not be loaded (python-matlab-bridge) or the package can not be installed at all (mlabwrap). I will give detailed information as soon as i try it again but the overall impression is: There is no easy way to install a simple Python package to use with Windows... – Mailerdaimon Apr 01 '14 at 12:44
  • In a try to get anything working i switched my setup to python2.7 and Matlab2011b. The problems i have with that are updated in my question. – Mailerdaimon Apr 01 '14 at 15:07

1 Answers1

1

I now got it working using python-matlab-bridge. I converted it by hand to Python3 and the changes have been merged into the official repo so it should work out of the box now.

If you get an error that 'messenger init' could not be found, make sure that Lib\site-packages\pymatbridge\matlab is in your PATH.

If you have any questions or additional information fell free to comment this answer and i will add it to help users get started with python-matlab-bridge.

Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46