Filter löschen
Filter löschen

How to configure MATLAB Web App Server to use Python?

18 Ansichten (letzte 30 Tage)
For MATLAB Desktop, I can follow this instruction to configure the system to use Python. 
How to do that for MATLAB Web App Sever apps? 

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 17 Apr. 2024
Bearbeitet: MathWorks Support Team am 17 Apr. 2024
By default, the application will use the Python environment setting inherited from the MATLAB session that compiled it. 
For example, on the development machine(Windows), pyenv set up information is below:
     Version: "3.9"
       Executable: "C:\Users\username\AppData\Local\Programs\Python\Python39\pythonw.exe"
          Library: "C:\Users\username\AppData\Local\Programs\Python\Python39\python39.dll"
             Home: "C:\Users\username\AppData\Local\Programs\Python\Python39"
           Status: NotLoaded
    ExecutionMode: OutOfProcess
 When the app is compiled on this Windows machine and then deployed to a Linux Web App Server, it will still try to use the Python interpreter from the above executable path and the program will generate error
FATAL ERROR: Python commands require a supported version of CPython
To properly configure Python environment for web app server apps,
1. Identify the python executable path on the server machine and make sure MwWebAppWorkerRxxxx account has access to your Python Installation. 
For example, you may do this on Windows by following the steps below:
  • Locate the Python folder in File Explorer, e.g.  C:\Users\<username>\AppData\Local\Programs\Python\Python38.
  • Right click and Select "Properties"
  • Go to the "Security" Tab
  • Click "Edit" and then "Add"
  • Clicked "Advanced" and in "From this location", select your computers hostname.
  • Click "Find now" and locate and select "MwWebAppWorkerR2020a" (or whichever is appropriate for your version of MATLAB)
  • You may now edit permissions for the Web App Server account used to run your web application. 
2. Add below code to your mlapp startup function
if isdeployed
%disp('setting python executable');
%for example,pyenv('Version','/usr/bin/python');
pyenv('Version','<path to python executable>');
end
Note: If you still receives error 
FATAL ERROR: Python commands require a supported version of CPython
or
FATAL ERROR: Error using pyenv
Path argument does not specify a valid executable.
please check if MwWebAppWorkerRxxxx account has access to your Python Installation.
3. If you get below error
Python is loaded. The environment cannot be changed while the interpreter is running. To change the environment, call 'terminate(pyenv)' then call 'pyenv'.
wrap any py. command in your mlapp with eval function. For example, demo=py.list('demo'), with “eval” like following: demo=eval("py.list('demo')").
Wrapping py command in eval prevents Python being loaded unexpectedly.

Weitere Antworten (0)

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by