- Install a supported version of Python on the server machine. Ensure that the account used to run MPS has access to this installation.
- Identify the path to the Python executable on the server (e.g. C:\Users\username\AppData\Local\Programs\Python\Python311\python.exe).
- Add the following code to the beginning of the MATLAB function you want to deploy, using the identified path: 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 isdeployedpyenv(Version="C:\Users\username\AppData\Local\Programs\Python\Python311\python.exe");end
How do I set up MATLAB Production Server (MPS) to use Python?
12 views (last 30 days)
Show older comments
MathWorks Support Team
on 5 Jan 2026 at 0:00
Answered: MathWorks Support Team
on 5 Jan 2026 at 20:44
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?
Accepted Answer
MathWorks Support Team
on 5 Jan 2026 at 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:
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?
0 Comments
More Answers (0)
See Also
Categories
Find more on Python Client Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!