Creating Standalone Application from App Designer Which Includes Python file.

6 views (last 30 days)
Hi everyone,
I've been troubleshooting this issue for a while now and am not sure where to go from here.
I've written an application in App Designer using MATLAB (2019a). The application itself uses Python to return data to MATLAB, in this particular case only being integer lists. Within App Designer, I can run my application perfectly. There are no issues with the Python files, and using:
py.importlib.import_module('mymod')
on my module produces no errors. A standard 64-bit CPython 3.7.5 is installed on my machine, and calling
pyversion
confirms that Python is both found, and loaded.
Inside of my App Designer applictation, and within the StartupFcn, I have updated the Python search path
pwd_path = pwd;
mod_name = 'py_dpd_add.py'; % yes, this is what I have called my module
full_path = [pwd_path, filesep, mod_name];
python_path = py.sys.path;
if count(python_path, full_path) == 0
insert(python_path, int32(0), full_path);
end
When I package my standalone application using the ApplicationCompiler, I add the Python file under 'Files installed for your end user'.
I have the standalone MATLAB Runtime 9.6 installed on my machine, and that is also the Runtime version within MATLAB.
Nonetheless, when I try to run my standalone application on the very same machine, the error I receive is
Undefined variable "py" or class "py.py_dpd_add.gen_dist"
Keep in mind this application is working perfectly when run within App Designer itself.
My only thought is that Python is not getting loaded within the application, but I tried adding the lines
pyversion('3.7'); % this works fine inside MATLAB itself
py.int(1); % checking to see if there are errors thrown, but there are not
to the script which adds the Python path, and there doesn't appear to be any issues resulting from these lines, which should theoretically imply Python is loaded.
If there is anyone who has experienced similar conufsion, or understands how to resolve this problem, I would greatly appreciate it.
Thanks for your time.
Edit: For what it's worth, the full traceback is as follows:
Undefined variable "py" or class "py.py_dpd_add.gen_dist".
Error in dpd_roll (line 42)
Error in Present_DPD/AddToPlotButtonPushed (line 412)
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 333)
Error in matlab.apps.AppBase>@(source,event)tryCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
  6 Comments
Eric Delgado
Eric Delgado on 15 Jul 2021
What did you do? I still don't know how to pack my app designed in Matlab with my Python modules. The app works perfectly inside Matlab!
But how to configure correctily pyenv in a client computer with more than one Python versions, for example? Or how to deal with a Matlab Run Time that did'n find a Python executable?
Arturo Pino
Arturo Pino on 12 Aug 2021
I have the same question. Have you run into any issues running pyenv() on app startup?
I'm particularly interested in installing an embedded python environment as part of my app's %APPDATA% directory and calling all python modules using that distribution since I can control which packages/versions are installed on the client's system. However, I'm having an issue where this works perfectly through the Matlab command window, and .m files. But when I try to set the pyenv() to the desired location through App Designer when starting the app, I get an error that the python environment is already loaded, even though I haven't executed a pyenv() command since restarting matlab.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!