MATLAB® automatically loads Python® when you type
py. in the
Command Window. If MATLAB displays this message, a failure has occurred.
Undefined variable "py" or function "py.command"
Use this page to help troubleshoot the failure.
A supported version of Python is not installed on your computer. Review Getting Started for your MATLAB version, then download and install Python from
On Microsoft® Windows®, Python downloads the 32-bit version of Python by default. If you run a 64-bit version of MATLAB, then download a 64-bit version of Python, identified by the name "Windows x86-64 MSI installer”. For more information, see Download 64-Bit Version of Python on Windows Platforms.
On Linux® and Mac systems, if you build Python from source files, then configure the build with the
You installed a 32-bit version of Python for a 64-bit version of MATLAB. You must install a 64-bit version of Python.
Python is in a nonstandard location. To provide the path to the Python executable, use the
pyversion function. For
On Windows systems, Python is not found in the Windows registry. If you downloaded a Python interpreter, but did not register it in the Windows registry, specify the Python location using the command:
An error occurred in the user-defined Python module. To test if your module,
If Python detects an error in the module, then MATLAB displays a Python error message.
Alternatively, execute the equivalent command at the Python command prompt to get the Python error message.
After you fix the error, to access the updated module, restart MATLAB, and add it to the search path.
command is a valid Python command, make sure the Python module is on the Python search path. To test if module
mymod is on the
If Python cannot find the module, MATLAB displays a Python error message.
mymod, in folder
to the path, type:
P = py.sys.path; if count(P,'modpath') == 0 insert(P,int32(0),'modpath'); end
The Python search path is associated with the Python interpreter loaded in the current session of MATLAB. You can modify the search path in MATLAB, but the modifications are not present if you run other instances of the interpreter outside of MATLAB.
If you call a Python module that has the same name as a module in the standard library or any 3rd-party modules installed on your system, then MATLAB might load the wrong module.
commandin Wrong Module
command is in a user-defined module, then make sure that
the module name does not conflict with modules in the Python standard library or any 3rd-party modules on your system.