I get an error when using numpy in my python script in simulink

조회 수: 49 (최근 30일)
Bastiaan
Bastiaan 2023년 10월 9일
편집: Bastiaan 2024년 1월 29일
I try to use a python script (version 3.11 according to the pyenv command) as a function in simulink. I use python importer and it works fine when not using numpy. As soon as I start the script with 'import numpy as np' however, the blocks don't work anymore and I get the error:
MATLAB System block 'Mytester21/taketwo2_CreateArrayfivedim' error occurred when invoking 'setupImpl' method of 'taketwo2_CreateArrayfivedim'.
Caused by:
  • Invalid HandleObjectRef - Entry not found in the server table
Component:Simulink | Category:Block error
The python script itself does not matter, as this issue arises with various different python files. Can anyone help me with this?
(an additional issue that I have is that I need to restart my computer every time I rework something in the python file, an update through obj.view does not update the simulink output.)
  댓글 수: 7
Abhishek
Abhishek 2024년 1월 26일
Any idea why this error occurs ? I am still not able to solve this error for my simulink model when python code with numpy or other imports is imported using the python importer toolbox
Bastiaan
Bastiaan 2024년 1월 29일
편집: Bastiaan 2024년 1월 29일
Sorry for the late reply, I was away for a while.
If I remeber correctly, the issue was that I hadn't installed python in the correct location. This meant that numpy wasnt installed in the correct location, so Matlab couldn't find the module. A coworker fixed it for me, so I am not 100% how to fix it exactly, but at least you now know a possible reason.
Another reason why this didn't work, was that the python file and generated matlab file have to be in the working directory. You can't generate a path to the python file (for some reason), so it has to be in the active folder.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by