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
2022 年 8 月 15 日
Python is run as an external program; MATLAB Compiler would not include the Python executable as part of the bundle.
回答 (2 件)
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 件のコメント
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!