How to solve error during Python Matlab integration using pymatlab?

3 ビュー (過去 30 日間)
Meera Girijan
Meera Girijan 2016 年 5 月 1 日
編集済み: wei du 2016 年 6 月 4 日
I am trying to call the matlab code written using python. After importing pymatlab, the next command session=pymatlab.session_factory() throws an error saying in line 51 an unexpected keyword argument "path" is encountered. I checked for online solutions where they asked me to change line 51 which was
session = MatlabSession(path=basedir,bufsize=output_buffer_size)
to :
session = MatlabSession(basedir,bufsize=output_buffer_size)
Even after doing this I am receiving the same error. Can anyone help me with this? least suggest another method for python matlab integration?
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 5 月 1 日
Try
session = MatlabSession(basedir,output_buffer_size)
Meera Girijan
Meera Girijan 2016 年 5 月 1 日
Tried that. The same error "__init__() got an unexpected keyword argument path" is displaying at the same line 51.

サインインしてコメントする。

回答 (2 件)

wei du
wei du 2016 年 6 月 4 日
編集済み: wei du 2016 年 6 月 4 日
I'm using Matlab R2012a 32Bit on Windows 10. I tried pymatlab and it works after some modification in matlab.py.
1. I set matlab_root to "C:\Program Files (x86)\MATLAB\R2012a" when I call pymatlab.MatlabSession.
2. I found out I have to change matlab directory to the dll_path of matlab to make sure the engine can be opened correctly. So I add codes below in pymatlab-0.2.3-py2.7.egg\pymatlab\matlab.py. After that, I can change the directory back.
3. If you want to use "session_factory", be careful of the path detected in "session_factory", it will be passed to "matlab.py" and you need to make sure libeng.dll and libmx.dll can be found in the path of "matlab.py".
dll_path = join(matlab_root, 'bin', 'win32')
os.chdir(dll_path)
self.engine = CDLL('libeng.dll')
self.mx = CDLL('libmx.dll')

Bo Li
Bo Li 2016 年 5 月 2 日
In case you are not aware of, Python Engine APIs can be used to call MATLAB functions from Python since R2014b:

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by