Installing matlab.engine API for Python in linux-based HPC

15 次查看(过去 30 天)
I want to use the HPC to accelerate my python-controlled Simulink.
Therefore, I have to install the matlab.engine on the HPC first.
Since my university's HPC only provides the Matlab-R2020a, so I have to use Python 2.7/ 3.6/ 3.7.
So I did the following steps. First I used Python 2.7
  1. cd /home/ViperAppsFiles/matlab/2020a/extern/engines/python/
  2. python setup.py build --build-base = /home/users/.cache install --prefix=/home/users/software
Now the whole module is built in software folder. Then I change the PYTHONPATH by:
export PYTHONPATH = /home/user/software/lib/python2.7/site-packages:$PYTHONPATH
But it reports the fault when I tried to call import matlab.engine:
Please contact MathWorks Technical Support for assistance:
Details: need more than 3 values to unpack
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/software/lib/python2.7/site-packages/matlab/__init__.py", line 209, in <module>
raise RuntimeError('unable to read {}'.format(get_arch_filename()))
RuntimeError: unable to read /home/user/software/lib/python2.7/site-packages/matlab/engine/_arch.txt
>>> RuntimeError: unable to read /home/user/software/lib/python2.7/site-packages/matlab/engine/_arch.txt
File "<stdin>", line 1
RuntimeError: unable to read /home/user/software/lib/python2.7/site-packages/matlab/engine/_arch.txt
^
SyntaxError: invalid syntax
And according to this method, the module only support 2.7, 3.8, 3.9, which 3.8 and 3.9 is incapable of cooperating with matlab/R2020a.

回答(1 个)

Ashu
Ashu 2023-1-27
Hi Jianing,
To install Python Engine you have to follow these steps -
1. Find the matlabroot by executing the following command at the MATLAB command window
matlabroot
2. change directory to :
<matlabroot>\extern\engines\python
3. Execute the follwing command with admin privilege :
python setup.py install
I would suggest you to use plain command like mentioned above, but if needed try the following for your use case:
python setup.py build -b <somedir> install
Then export the path if needed.
For more information on matlab.engine for python you can refer
Regards
Ashutosh
  2 个评论
Jianing
Jianing 2023-1-27
Thanks for you time. Now the Matlab.engine has installed on the HPC server and could be called.
However, only these two commands could work.
>>> import matlab.engine
>>> env = matlab.engine.start_matlab()
When I started to call the real simulink file as follows:
>>> env_name = 'TEST_2020'
>>> env.load_system(env_name)
Then the error is as:
Caught "std::exception" Exception message is:
libasound.so.2: cannot open shared object file: No such file or directory: Success: Success
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/722179/.conda/envs/matlab_python_37/lib/python3.7/site-packages/matlab/engine/matlabengine.py", line 71, in __call__
_stderr, feval=True).result()
File "/home/722179/.conda/envs/matlab_python_37/lib/python3.7/site-packages/matlab/engine/futureresult.py", line 67, in result
return self.__future.result(timeout)
File "/home/722179/.conda/envs/matlab_python_37/lib/python3.7/site-packages/matlab/engine/fevalfuture.py", line 82, in result
self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
matlab.engine.MatlabExecutionError: libasound.so.2: cannot open shared object file: No such file or directory: Success: Success
Could you please tell me where went wrong?
Ashu
Ashu 2023-1-27
编辑:Ashu 2023-1-27
It says no file or directory found. Can you confirm if the env exists at the current directory?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Call MATLAB from Python 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by