I’m getting “Error using feval Unrecognized function or variable 'py.dict” when trying to use pyrunfile or pyrun.
I’m running Matlab version: '24.2.0.2923080 (R2024b) Update 6' on a 16” 2023 Apple M2 Max with Sonoma 14.7.2 I installed python by downloading the dmg from python.org for version 3.12 and installing it. I can run python functions and modules using the “py.” prefix, but can’t run anything using pyun or pyrunfile. I’m not sure if I need to use those functions but a worried something might be wrong. Any suggestions are appreciated.
I looked through various posts about this error to verify that I have a compatible version of python with the “arm” version:
pyenv
ans =
PythonEnvironment with properties:
Version: "3.12"
Executable: "/usr/local/bin/python3"
Library: "/Library/Frameworks/Python.framework/Versions/3.12/lib/libpython3.12.dylib"
Home: "/Library/Frameworks/Python.framework/Versions/3.12"
Status: Loaded
ExecutionMode: OutOfProcess
ProcessID: "54235"
ProcessName: "MATLABPyHost"
And from the python command line:
>>> import platform, subprocess
>>> platform.processor()
'arm'
I can run the sample test program in a file called df1.py:
def myfunc():
return 'version 1'
By typing:
a= py.df1.myfunc
a =
Python str with no properties.
version 1
I can change the python code (to return 2) and reload it and get:
a= py.df1.myfunc
a =
Python str with no properties.
version 2
But if I try to run the file using pyrunfile, I get an error:
pyrunfile('df1.py')
Error using feval
Unrecognized function or variable 'py.dict'.
Same with pyrun:
res = py.list({"Name1","Name2","Name3"})
res =
Python list with values:
['Name1', 'Name2', 'Name3']
Use string, double or cell function to convert to a MATLAB array.
pyrun('res = list({"Name1","Name2","Name3"})')
Error using feval
Unrecognized function or variable 'py.dict'.
Any suggestions are appreciated.