- 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:
Can I call a Python module from a web app running on Web App Server?
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 23 Juil 2020
Modifié(e) : MathWorks Support Team
le 19 Juil 2022
I have created a web app using App Designer that calls a Python module like so:
py.myModule.myFunction()
The app appears to work when run in MATLAB, but when I deploy it to Web App Server, I get an error in the web app log stating:
Unable to resolve the name py.myModule.myFunction.
Réponse acceptée
MathWorks Support Team
le 14 Juil 2022
Modifié(e) : MathWorks Support Team
le 19 Juil 2022
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:
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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Web App Server dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!