Unable to resolve the name py.myfunc
MATLAB® automatically loads Python® when you type py.
followed by a Python statement at the MATLAB command prompt. If MATLAB displays this message, a failure has occurred for the call to
myfunc
.
Unable to resolve the name py.myfunc
Use this page to help troubleshoot the failure.
Python Not Installed
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/
.
On Linux® and Mac systems, if you build Python from source files, then configure the build with the
--enable-shared
option.
To verify if Python is installed on your system, check the PythonEnvironment
Version
property.
pe = pyenv; if isempty(pe.Version) disp "Python not installed" end
64-bit/32-bit Versions of Python on Windows Platforms
You installed a 32-bit version of Python for a 64-bit version of MATLAB. You must install a 64-bit version of Python.
MATLAB Cannot Find 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:
pyenv(Version="executable")
Error in User-Defined Python Module
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 statement 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.
Python Module Not on Python 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.
Module Name Conflicts
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.
Python Tries to Execute myfunc
in Wrong Module
If 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.