MATLAB® automatically loads Python® when you type py.
followed by a Python command at the MATLAB command prompt. If MATLAB displays this message, a failure has occurred for the command
myfunc
you tried to execute.
Unable to resolve the name py.myfunc
Use this page to help troubleshoot the failure.
A supported version of Python is not installed on your computer. Review Configure Your System to Use Python
for your MATLAB version, then download and install Python from https://www.python.org/downloads/
.
To install version 2.7 for 64-bit MATLAB on Microsoft® Windows® systems, select the 64-bit Python version, called Windows x86-64 MSI installer.
On Linux® and Mac systems, if you build Python from source files, then configure the build with the
--enable-shared
option.
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 pyenv
function.
For example:
pyenv('Version','C:\Users\uname\WinPython-64bit-3..2.1\python-3..2.amd64\python.exe')
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:
pyenv('Version','executable')
An error occurred in the user-defined Python module. To test if your module, mymod
, contains
errors, type:
py.importlib.import_module('mymod')
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.
If 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
path, type:
py.importlib.import_module('mymod')
If Python cannot find the module, MATLAB displays a Python error message.
To add mymod
, in folder modpath
,
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.
myfunc
in Wrong ModuleIf myfunc
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.