How can I properly create an standalone APP which includes python .py scripts?
47 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 15 de Ag. de 2022
Python is run as an external program; MATLAB Compiler would not include the Python executable as part of the bundle.
Respuestas (2)
Eric Delgado
el 26 de Sept. de 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
2 comentarios
Eric Delgado
el 20 de Jul. de 2024
Editada: Eric Delgado
el 20 de Jul. de 2024
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
el 7 de Mzo. de 2024
Editada: Kevin Rusch
el 7 de Mzo. de 2024
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.
0 comentarios
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!