How can I properly create an standalone APP which includes python .py scripts?

조회 수: 47 (최근 30일)
Hello, I am facing difficulties to properly compile an standalone Matlab APP which includes python .py scripts. It works fine inside Matlab 2022a environment, however the standalone APP (from APP Designer) does not work, it sounds a beep and the .py scripts don´t run properly. Is there a guide or educational material that I could follow to make that in the proper way?
Is there something that I should include in the Startup FCN ?
Thanks,
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 8월 15일
Python is run as an external program; MATLAB Compiler would not include the Python executable as part of the bundle.
Fernando Sarracini Júnior
Fernando Sarracini Júnior 2022년 8월 15일
The .py files are copied inside the same folder of Matlab APP executable file. I am using pyrunfile to call the .py files like below. I have python installed in my computer (confirmed with pe = pyenv).
[res, vectorf] = pyrunfile("vscs_compilation.py", ["z", "vectorf"], file = file_final)
It works fine inside Matlab, however the standalone executable file does not work. Am I missing anything?
Thanks,

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

답변 (2개)

Eric Delgado
Eric Delgado 2022년 9월 26일
Look... pyenv will give you the Python environment used to call your .py files. Ok. But... when you run a standalone version of your app, you should be aware that the machine running the app could not have a Python installation (or could have one, but without all required libs). And you do have to point to the correct Python environment (inside your Matlab Runtime or Matlab+Compiler).
I had to deal with this issue... and the solution was to give the user the possibility to change the Python environment (because by default Matlab will point to the "base environment" of the Python installed). So... this is the callback for a "python button" pushed that I put in my apps.
% Button pushed function: version_python
function version_pythonPushed(app, event)
Python = pyenv;
[file, pathfile] = uigetfile({'python*.exe', 'python*.exe'}, 'Choose the Python executable file...', Python.Executable);
if file
try
Python = pyenv('Version', fullfile(pathfile, file));
catch ME
MessageBox(app, 'error', getReport(ME))
end
end
end
  댓글 수: 2
Mani
Mani 2024년 7월 19일
편집: Mani 2024년 7월 19일
Does your app work when it's running on the third party machine without MATLAB installed? I did the same (asking user to enter the python path), but the app is failing to fetch python executive.
Had you done any additional tweak?
Eric Delgado
Eric Delgado 2024년 7월 20일
편집: Eric Delgado 2024년 7월 20일
I understand that you are running a standalone version of an app built in AppDesigner, and for that, the user has installed MATLAB Runtime on their machine, correct?
Additionally, the user must install Python (I always suggest Miniconda) and create the virtual environment from which they should locate the "python.exe" file, mapping it in MATLAB Runtime.
pyenv('Version', 'C:\Users\userName\.conda\envs\envName\python.exe'); % (using conda default path in Windows)
Read the answer below provided by Mathworks Support Team:

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


Kevin Rusch
Kevin Rusch 2024년 3월 7일
편집: Kevin Rusch 2024년 3월 7일
The way to accomplish what you're looking for is by using a tool like pyinstaller to convert your python files into standalone executables, leveraging MATLAB's isdeployed, ispc, ismac, and isunix functions to alter the call you make within your app, and packaging your python and MATLAB standalones using any of many third party solutions. This way your code should work regardless of your user's environment.
You still won't end up with a single standalone app in the end, but you'll have a single package that creates a directory on the user's system that will execute your code as intended.

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by