Yes, you can call Python modules from deployed web apps.
First make sure your web app is configured to run python by following this instruction .
About the specific error for a python module:
Unable to resolve the name py.myModule.myFunction.
It indicates that Python cannot find the module on the PYTHONPATH.
There are different solutions:
Solution 1.
You can package the Python module (.py file) into the web app server .ctf file. To do so:
- When packing the ctf file with deploytool, add the Python module to "Files required for your app to run". Or -a the Python module when packaging with mcc.
- In the app designer startup function add the following code:
if isdeployed
[filepath,~,~] = fileparts(mfilename('fullpath'));
insert(py.sys.path, int64(0), filepath);
end
Solution 2.
If you don't want to package the Python module into the web app .ctf file, you will need to add the directory containing your Python module to the PYTHONPATH system environment variable. (If it is not defined, you can simply create it.)
Note that since Web App Server runs under a different user account, you will need to define PYTHONPATH as a system environment variable, not a user environment variable, so that it applies to all users.
Furthermore, the account from which Web App Server runs must have permission to access the folder containing your Python module. For example, you can put the python module file in the same folder as where the web app server ctf file is, namely the web app server app folder (e.g., C:\ProgramData\MathWorks\webapps\R2021b\apps).
After setting up the environment variable, restart web app server.