How do I set up MATLAB Production Server (MPS) to use Python?

9 Ansichten (letzte 30 Tage)
I have a MATLAB function that calls Python, which I would like to deploy to MATLAB Production Server (MPS). For MATLAB Desktop, I can follow these instructions to configure the system to use Python. 
How can I do this for code running on MATLAB Production Server? 

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 5 Jan. 2026 um 0:00
Note that this answer is about setting up Python for use in deployed code (e.g. using py. or pyrun) on MATLAB Production Server. For information on setting up the Python client for MATLAB Production Server, see this documentation
To properly configure the Python environment to be used when running deployed code on MATLAB Production Server:
  1. Install a supported version of Python on the server machine. Ensure that the account used to run MPS has access to this installation. 
  2. Identify the path to the Python executable on the server (e.g. C:\Users\username\AppData\Local\Programs\Python\Python311\python.exe).
  3. Add the following code to the beginning of the MATLAB function you want to deploy, using the identified path: 
    if isdeployed
    pyenv(Version="C:\Users\username\AppData\Local\Programs\Python\Python311\python.exe");
    end
    This will configure this code to use the correct Python installation when running on MATLAB Production Server. This should be added to all deployed functions that use Python. 
If you encounter unexpected behavior or errors during execution of Python code on MPS, see Why does my MATLAB Production Server request sometimes fail for CTFs that use Python?

Weitere Antworten (0)

Tags

Noch keine Tags eingegeben.

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by