MATLAB Answers

Is it possible to compile MATLAB programs that contain Python code using MATLAB Compiler?

64 views (last 30 days)
I tried compiling my MATLAB program with Python code into a standalone application, but got the following error message when running it:
Undefined variable "py" or function "py.command"

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Aug 2019
Edited: MathWorks Support Team on 13 Aug 2019
Yes, this workflow is supported.
But please pay attention to what mentioned in the link below before compiling your code:
A possible cause for this error is that the Python module is on the Python search path.


Matthew Parrilla
Matthew Parrilla on 17 Jul 2018
Glad to hear this workflow is supported, can you explain how to do it?
My installed executable doesn't contain my python code, so the script cannot find the Python module I'm calling from my compiled Matlab script.
When I manually add the python file to the "application" directory my executable has been installed to, it works just fine.
My mcc commands include `-a C:\path\to\` but I had to select that file manually as the deploytool did not find it.
Just to clarify I:
  • have python installed
  • have the 64bit version of python
  • matlab CAN find python (I can print py.sys.path, for example)
  • there isn't an error in the module (I can run it from regular Matlab just fine)
  • there are no module name conflicts
It sure does seem to me like a bug w/ Matlab, but I'd love to be shown otherwise!

Sign in to comment.

More Answers (1)

Sarah Crimi
Sarah Crimi on 28 Jan 2019
I had this problem as well. I had to manually add the Python files to the folder of the executible.


Sign in to comment.


No tags entered yet.