How to use Python on Webapp Server running on Windows?

7 visualizzazioni (ultimi 30 giorni)
I have created predict.py and added to .ctf, In startup I have used following code
if isdeployed
pyenv(Version="C:\Users\MatlabWebAppVM\AppData\Local\Programs\Python\Python39");
[filepath,~,~] = fileparts(mfilename('fullpath'));
insert(py.sys.path, int64(0), filepath);
end
Getting this error while running on server

Risposte (1)

Rushikesh
Rushikesh il 8 Ott 2024
Modificato: Rushikesh il 8 Ott 2024
Hello,
I understand that you're trying to execute Python code within a MATLAB Web App by setting the 'pyenv' version in the 'startupFcn'. However, you're encountering a long loop that ends with a "Something went wrong" error. This error typically occurs when the MATLAB Web App Server is unable to access the Python installation directory.
The MATLAB Web App Worker account, named “MwWebAppWorkerR2024a” (replace with the appropriate version for your MATLAB installation), needs permission to access your Python executable directory.
Here's how you can set the necessary permissions on Windows:
  1. Open File Explorer and navigate to the Python installation directory, for example, C:\Users\username\AppData\Local\Programs\Python\Python39.
  2. Right-click on the Python folder and select "Properties."
  3. Go to the "Security" tab.
  4. Click "Edit," then "Add."
  5. Click "Advanced," and under "From this location," select your computer's hostname (you can find your hostname by typing hostname in the Command Prompt).
  6. Click "Find Now," locate, and select "MwWebAppWorkerR2024a" (or the appropriate account for your MATLAB version).
  7. Grant the necessary permissions to the Web App Server account to allow it to run your web application.
I've attached a screenshot of the “Properties > Security > Edit > Add” window for clarity. For more detailed instructions on configuring the MATLAB Web App Server to use Python, you can refer to the below MATLAB Answer.
Hope this helps you.

Community Treasure Hunt

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

Start Hunting!

Translated by