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

14 views (last 30 days)
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 Comments
Fernando Sarracini Júnior
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,

Sign in to comment.

Answers (1)

Eric Delgado
Eric Delgado on 26 Sep 2022
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

Community Treasure Hunt

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

Start Hunting!

Translated by