- 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 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 7월 23일
편집: MathWorks Support Team
2022년 7월 19일
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.
채택된 답변
MathWorks Support Team
2022년 7월 14일
편집: MathWorks Support Team
2022년 7월 19일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Web App Server에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!