arokem / python-matlab-bridge

A simple Python => MATLAB(R) interface and a matlab_magic for ipython
BSD 2-Clause "Simplified" License
335 stars 96 forks source link

fail to start MATLAB #125

Closed willard-yuan closed 9 years ago

willard-yuan commented 9 years ago

After installing the package python-matlab-bridge and pyzmq, I try to use the pymatbridge by the Usage instruction:

Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from pymatbridge import Matlab
>>> mlab = Matlab()
>>> mlab = Matlab(executable='D:\Program Files\MATLAB\R2014b\bin\matlab')
>>> mlab.start()
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
False

I don't know the reason, someone else has the problem?

arokem commented 9 years ago

Thanks for reporting your problems, and sorry to hear that this is not working for you. What you should be seeing is something like the following:

    >>> from pymatbridge import Matlab

    >>> mlab = Matlab(executable='/Applications/MATLAB_R2014b.app/bin/matlab')

    >>> mlab.start()

    Starting MATLAB on ZMQ socket ipc:///tmp/pymatbridge

    Send 'exit' command to kill the server

    .MATLAB started and connected!

    True

    >>>

                            < M A T L A B (R) >

                  Copyright 1984-2014 The MathWorks, Inc.

                   R2014b (8.4.0.150421) 64-bit (maci64)

                             September 15, 2014

    To get started, type one of these: helpwin, helpdesk, or demo.

    For product information, visit www.mathworks.com.

     Socket created at: ipc:///tmp/pymatbridge

That is, the matlab application should start in that terminal. Just to be sure, what happens when you type just this:

D:\Program Files\MATLAB\R2014b\bin\matlab

In your terminal (not in python)?

willard-yuan commented 9 years ago

when I type the 'D:\Program Files\MATLAB\R2014b\bin\matlab' in the DOS cmd, it says no command found. So I add the path 'D:\Program Files\MATLAB\R2014b\bin' to windows environment, then type it again. It works and open MATLAB.

Then I run the following commands:

>>> from pymatbridge import Matlab
>>> mlab = Matlab(executable='matlab')
>>> mlab.start()

after I type mlab.start() and press Enter button, a windows is opening. The content in the windows is as follows:

MATLAB is running in headless mode.  Figure windows will not be displayed.

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

old_warning_state = 

16x1 struct array with fields:
    identifier
    state

Invalid MEX-file 'C:\Python27\lib\site-packages\pymatbridge\matlab\messenger.mexw64': XXXX

Error in matlabserver (line 7)
messenger('init', socket_address);

and still can't connect to matlab:

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
False
arokem commented 9 years ago

There seems to be something wrong with the Windows messenger. Might be related to issue reported here: https://github.com/arokem/python-matlab-bridge/pull/123. Unfortunately, I don't have a Windows machine to figure this out with, but this page might be helpful:

http://stackoverflow.com/questions/23716426/installing-pymatbridge-on-windows

On Mon, Feb 2, 2015 at 4:15 AM, Yong Yuan notifications@github.com wrote:

when I type the 'D:\Program Files\MATLAB\R2014b\bin\matlab' in the DOS cmd, it says no command found. So I add the path 'D:\Program Files\MATLAB\R2014b\bin' to windows environment, then type it again. It works and open MATLAB.

Then I run the following commands:

from pymatbridge import Matlab>>> mlab = Matlab(executable='matlab')>>> mlab.start()

after I type mlab.start() and press Enter button, a windows is opening. The content in the windows is as follows:

MATLAB is running in headless mode. Figure windows will not be displayed.

To get started, type one of these: helpwin, helpdesk, or demo. For product information, visit www.mathworks.com.

old_warning_state =

16x1 struct array with fields: identifier state

Invalid MEX-file 'C:\Python27\lib\site-packages\pymatbridge\matlab\messenger.mexw64': XXXX

Error in matlabserver (line 7) messenger('init', socket_address);

and still can't connect to matlab:

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 False

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/125#issuecomment-72448076 .

willard-yuan commented 9 years ago

I try to run it in Ubuntu, and I still face a problem:

>>> mlab.start()
Starting MATLAB on ZMQ socket ipc:///tmp/pymatbridge
Send 'exit' command to kill the server
Invalid MEX-file
'/usr/local/lib/python2.7/dist-packages/pymatbridge/matlab/messenger.mexa64':
libzmq.so.3: cannot open shared object file: No such file or directory

But I have install the pyzmq. I have test it:

import zmq

It's ok. Can you tell me how to make it run?

willard-yuan commented 9 years ago

After modifying the path in make.py and make the file, It's ok.

arokem commented 9 years ago

Seems like this is resolved. Closing it for now

vaibhaw commented 9 years ago

I installed pymatbridge using pip on Ubuntu 12.04 64bit machine with Python 2.7 I was also getting the following error:

Invalid MEX-file '/usr/local/lib/python2.7/dist-packages/pymatbridge/matlab/messenger.mexa64': libzmq.so.3: cannot open shared object file: No such file or directory

I think the reason for this error is that pip copies the precompiled messenger.mexa64 in python2.7/dist-packages/pymatbridge/matlab directory. This precompiled library was linked to libzmq.so.3 while I had lizmq.so.4 installed on my machine.

The solution is to compile this messenger binary on your machine. (Instructions for Linux)

# 1. Clone the python-matlab-bridge repo
git clone https://github.com/arokem/python-matlab-bridge.git
# 2. Change path of matlab/bin directory in python-matlab-bridge/messenger/mexa64/local.cfg
# In my case matlab was installed in /usr/local/MATLAB/R2013a/bin
# 3. Compile 
cd python-matlab-bridge/messenger
python make.py matlab

If libzmq and pyzmq is installed on your machine, new mex would be correctly linked to the libzmq binary installed on your machine.

Finally install python-matlab-bridge:

cd ..
python setup.py install
arokem commented 9 years ago

By the way, the compiled zmq4 binaries are now in the source distribution:

https://github.com/arokem/python-matlab-bridge/commit/90fea89df82c717900ef21405886305b0ee74dad

so you don't even need to compile them yourself, but you will have to copy the messenger.mexa64.zmq4 file into messenger.mexa64 file, so that it's used.

mnarayan commented 9 years ago

The current master still isn't working for me. I still have linking issues with libzmq.so.3 despite having the library. I also tried to mex messenger as @vaibhawchandel suggested but I still get the following error.

Building messenger.mexa64...
"/opt/rice/matlab-2013b/bin/mex" -O -L. -I. -lzmq ./src/messenger.c

Traceback (most recent call last):
  File "make.py", line 108, in <module>
    build_matlab(static=args.static)
  File "make.py", line 93, in build_matlab
    do_build(make_cmd, 'messenger.%s' % extension)
  File "make.py", line 53, in do_build
    subprocess.check_output(shlex.split(make_cmd), shell=True)
  File "/opt/local/bin/anaconda/lib/python2.7/subprocess.py", line 573, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/opt/rice/matlab-2013b/bin/mex', '-O', '-L.', '-I.', '-lzmq', './src/messenger.c']' returned non-zero exit status 255

Within matlab (version 2013b) I get this

>> cd pymatbridge/matlab
>> addpath(genpath('.'))
Warning: Function isrow has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name
conflict. 
> In path at 110
  In addpath at 87 
>> matlabserver('ipc:///tmp/pymatbridge')
Invalid MEX-file '/home/xxx/src/pymatbridge-0.4.3/pymatbridge/matlab/messenger.mexa64': libzmq.so.3: cannot open shared object
file: No such file or directory

Error in matlabserver (line 7)
messenger('init', socket_address);
blink1073 commented 9 years ago

@mnarayan, can you try running that command directly from the shell prompt in the messenger directory and paste what you get?

mnarayan commented 9 years ago

It turns out that when I run the mex command from within matlab and link to libraries, I am able to compile messenger.mexa64.

mex -O -L/home/xxx/bin/lib/ -I/home/xxx/bin/include -lzmq src/messenger.c

However, matlabserver still cannot find libzmq.so.3 apparently; despite having the latest installation of pyzmq


>> matlabserver('ipc:/tmp/pymatbridge') 
Invalid MEX-file '/home/mn4/src/python-matlab-bridge/build/lib/pymatbridge/matlab/messenger.mexa64': libzmq.so.3: cannot open
shared object file: No such file or directory

Error in matlabserver (line 7)
messenger('init', socket_address);
blink1073 commented 9 years ago

@mnarayan, it looks like you may need to set LD_LIBRARY_PATH to wherever zmq is located.

mnarayan commented 9 years ago

I do have LD_LIBRARY_PATH set to libzmq locations. This doesn't seem to resolve the linking issues.

I downgraded to pymatbridge 0.3 which seemed to resolve library linking issues. However ipython 3 notebooks don't seem to be able to return results from matlabserver to the notebook. This seems to be a notebook issues since I am able to use matlab magic within ipython. ipython 2 notebooks don't seem to have any problems however, so I will stick to that.

blink1073 commented 9 years ago

Sorry @mnarayan, I'm out of ideas.

arokem commented 9 years ago

Hi @mnarayan - sorry that this wasn't working for you! You might want to give it another try with the current master. The recent merge contains a messenger that has been statically linked to libzmq.

On Thu, Apr 2, 2015 at 5:45 PM, Steven Silvester notifications@github.com wrote:

Sorry @mnarayan https://github.com/mnarayan, I'm out of ideas.

— Reply to this email directly or view it on GitHub https://github.com/arokem/python-matlab-bridge/issues/125#issuecomment-89094793 .

moritzmcgarrie commented 9 years ago

The question for me is how to call the exact path when using %load_ext pymatbridge ?

On a mac with python3.4 if I run it with matlab = pymat.Matlab() then I get "/bin/sh: matlab: command not found" ... So it seems that it attempts to run in the original Bourne Shell (sh) in which one cannot define an alias, instead of the BASH shell in which my alias is "alias matlab='/Applications/MATLAB_R2014a.app/bin/matlab -nojvm' " . The resolution is to write,

matlab = pymat.Matlab('/Applications/MATLAB_R2014a.app/bin/matlab') matlab.start()

Which works nicely! So with that resolved, the issue is I want to get matlab_magic to work and if I type %load_ext pymatbridge In ipython notebook I get
"ValueError: MATLAB failed to start"

So how do I use magic with matlab_magic? Plus maybe it would be better if the code took the address of matlab directly in the notebook, rather than through an alias in a shell script. thanks

blink1073 commented 9 years ago

you could create a symbolic link in your current directory the points to the real matlab, or put it in ~/bin and add that to your path.

moritzmcgarrie commented 9 years ago

Yes thanks! For those learners like me, the Symbolic link solution was to cd to ~/bin and then write " sudo ln -s /Applications/MATLAB_R2014a.app/bin/matlab matlab " This created for me a symbolic link in the folder bin called matlab which went to the above address (type "man ln" in terminal for details)

ilciavo commented 9 years ago

Great thanks, It wasn't working with matlab = pymat.Matlab(executable='/Applications/MATLAB_R2014a.app/bin/matlab') but doing matlab = pymat.Matlab('/Applications/MATLAB_R2014a.app/bin/matlab') worked Is the %%matlab magic supposed to work after installing? I get: ERROR: Cell magic %% not found.

yw5aj commented 8 years ago

I had the same problem w/ OP. The issue is, the space in the path makes the shell thinks that it is separated arguments. I put in mlab = Matlab(executable='\"C:/Program Files/MATLAB/R2013b/bin/matlab.exe\"') and it worked file.