How to compile a Standalone App which requires Python?

I am trying to compile a Standalone App with App designer.
The goal should be that other user can open the App without having Matlab installed.
The App workes on App Designer perfectly. Even if I compile the App and open it on my computer everything runs.
However, if I open the App on an other computer (without MATLAB, Python and CoolProp) the App opens but the calculation can't be done.
I guess the problem is the missing Python and/or CoolProp on the second Computer.
My code uses this function:
rho=py.CoolProp.CoolProp.PropsSI('D','T',273.15+ T_gc_out ,'P',p_h,KM)
Is there a way to compile the App including the required Python and CoolProp software to run my programm? I want to include these files, or codes in the app such that the other users don't have to download Python and CoolProp separately.

1 Comment

I think you could rather use websave to download Python directly to app root directory from this link, take a look at embeddable package, it's an archive file that you could unpack through MATLAB and use pyenv with input arguments to specify the location of the Python executable. Maybe you could do similarly for CoolProp, I don't know what is it.

Sign in to comment.

Answers (3)

Hi Giancarlo
As of R2021a, MATLAB doesn't support including external software when deploying an application automatically. However, as Mario suggested, you can try including the embeddable package of python. Note that it does not contain pip to install other packages. Hence, you also need to use the manual local installation instructions present in the CoolProp documentation.
Hope this helps

2 Comments

I want to do the same thing i.e. compile a Standalone App with App designer which uses some python functions.
Do I understand correctly that I need to ensure that the embeddable version of python is installed with the correct packages? Does that still work or does matlab does not support this anymore?
I haven't build the App but I'm considering App designer and I don't want to do the effort and afterwards realise it can't be done.
I do not know if this still works. I am not using Matlab anymore. If you anyways are going to use Python functions, then it is maybe easier to create the UI with Python (Tkinter?) and not using the Matlab app builder.

Sign in to comment.

I found a way to do so.
I added an "install" button in my app to run
pe = pyenv
app.PyversionEditField.Value = pe.Version %to print the version of python
[v,e] = pyversion; system([e,' -m pip install --user -U CoolProp']) %to install CoolProp
it does the trick
Do you know how to run this three lines of code without having a button? I would like it to run whenever opening the app

10 Comments

You can put it in StartupFcn callback.
Avoid using pyversion as that function is not recommended.
I have exactly the same problem as you have, and it tried to solve it like you did. But unfortunately when compiling and installing my application on another computer, I am still not able to call the Coolprop command ("py.CoolProp.CoolProp.PropsSI..."). Instead I even get an error beforehand when trying to install Coolprop: It tells me that the command "-m" must be misspelled or can't be found. Python is installed, but somehow the command "system([e,' -m pip install --user -U CoolProp'])" can't be processed... have you had this error too? If so, what did you do in order to solve it?
My main PC runs MATLAB 2022a and Python 3.8.10.
My second PC where the application is supposed to run only runs Python 3.8.10.
Thank you for your help in advance!
Hello Alexander,
I installed anaconda on my computer. Try to run
pyversion C:\User\..\anaconda3\python.exe
When installing anaconda make sure to install it for "all users". I run into the same issue when anaconda was not installed for all users.
Let me know if you had any success.
Thanks for the quick answer!
Ok, I installed Anaconda3 for "all users" - same problem.
I guess you mean I should run "pyversion C:\User\..\anaconda3\python.exe" on the PC with MATLAB, am I right? Or do you mean I should implement this code into my Code of my application?
Now it is Python 3.9, do you think it has something to do with the python version? Or even with MATLAB 2022a?
And: have you needed the above mentioned embeddable package? Because I haven't implemented it yet...
Install Anaconda for all users on the computer without MATLAB.
Include in StartupFCN callback (or "install button") these two lines.
pe = pyenv
[v,e] = pyversion; system([e,' -m pip install --user -U CoolProp']) %to install CoolProp
Now everytime the application is started these lines are executet. You could even check the system if CoolProp already exist. If not install it. I would recommend that, it makes your application faster.
The approach with an "install button" is not bad, however, for the clients it could look cheap. Use the install button just for testing purposes.
Thank you. I tried your code, but it errored. After a lot (!) of try and error I figured out, that I would need to change the code for automatically installing CoolProp a little bit:
pe = pyenv
[v,e] = pyversion; system([e,'python -m pip install --user -U CoolProp']) %to install CoolProp
Otherwise I would get the error, that the command "-m" is unfamiliar. My Python Version is 3.8.10 on every PC and it only worked when installing Python directly, not using Anaconda. But as you mentioned: directly installing CoolProp works faster and I would recommend it too.
Solved this problem, ran into the next one: When running the function
rho=py.CoolProp.CoolProp.PropsSI('D','T',...)
I get the error "Python commands require a supported version of CPython". Have you had this problem too?
Edit: I had to set up my PC newly in order to make the code run - did nothing with the code, just reinstalled my main PC. Somehow - and I really don't know why - when compiling my application with it, the other PC's take the location of the installed Python version of the compiling PC. Because the location of Python on the compiling PC was another one than the one on the other PC's I got basically the message, that there was no Python on this PC, because the savepath it searched for - which did not exist on the other PC's - had no Python version in it.
Thank you for your help Giancarlo!
Hi all,
I have the same problem as Alexander Heinold. Can some one help or Alexander what to do. I reinstall everything but have the same problem again CPython. I think i need to change the path on the other computer in CMD or powershell but i don't know how?
Hi @Tazura1998, MATLAB has a setenv function which could be used in your case.

Sign in to comment.

hsin-yu
hsin-yu on 16 Feb 2024
Edited: hsin-yu on 16 Feb 2024
I also encountered the same problem. I compiled the thermal property calculation APP on a computer with MATLAB, and packaged the APP and sent it to a user who did not have MATLAB. The user had python installed, but the python environment status was detected as not loaded. Therefore it cannot be calculated.
Is this because the APP cannot execute the command window ?
If the APP has this limitation, how to solve it?
------------------<my code>---------------------------------------------------------------
% Prompt the user for the Python installation directory and provide examples
default_python_dir = 'C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe';
python_dir_cell = inputdlg('Please enter the directory where Python executable is located:', 'Python Directory', [1, 100], {default_python_dir});
python_dir = char(python_dir_cell);
% If the user cancels input, return
if isempty(python_dir)
return;
end
try
% Try to execute pyenv
pe = pyenv("Version", python_dir);
% Display Python environment information
disp(pe);
% Convert Python environment information to a string
pe_str = evalc('disp(pe)');
% Display Python environment information string
msgbox(pe_str, 'Python Environment');
% Determine whether to import CoolProp based on whether Python status is loaded
if strcmp(pe.Status, 'Loaded')
% Try to install CoolProp
[v, e] = pyversion;
cmd = [e, ' -m pip install --user -U CoolProp'];
system(cmd);
pause(0.1);
% Display success message box
msgbox('Connected successfully.', 'Success');
else
% Show error message box
msgbox('Python is not loaded. Please make sure Python version supports MATLAB.', 'Error');
end
catch ME
% If an error occurs, display an error message box
errorMessage = ME.message;
msgbox(errorMessage, 'Error', 'error');
end

Products

Release

R2020b

Asked:

on 23 Mar 2021

Commented:

on 19 Jul 2024

Community Treasure Hunt

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

Start Hunting!