0

I am trying to call python from Matlab using its python interface. I am first setting the env then calling a simple example but am getting an error:

pyenv('Version', ... 
  '../bin/python', ... 
  'ExecutionMode','OutOfProcess') 

pyrun("l = ['A','new','list']")  
l

Error using feval
Unrecognized function or variable 'py.dict'.
2
  • What version of MATLAB are you using? What version of Python is ../bin/python? Commented Apr 9, 2023 at 2:52
  • This might be a dupe target: stackoverflow.com/q/37152895/7328782 — Does that solve your issue? Commented Apr 9, 2023 at 2:56

1 Answer 1

0

This indicates that something is not setup correctly between Python and MATLAB and is NOT something specific to py.dict.

My test case was wtf = py.list(1:2)

When you are specifying the Python path my understanding is the 3 problems you are most likely to see, if the executable exists, are either:

  1. An unsupported Python version : https://www.mathworks.com/support/requirements/python-compatibility.html
  2. A mismatch between 32 bit and 64 bit
  3. A mismatch between ARM and Intel. This was my problem. I think for 2023b macs MATLAB is running ARM (for apple silicon macs).

In python run:

import platform, subprocess
platform.processor()

If it comes back i386 (or not arm) then you are probably using an Intel compiled Python version. For me I had to download a new version of Anaconda Navigator being careful to download the "M1" version (they offer both M1 and Intel and both might install). From there I installed a new environment. This put together a new Python that was using arm.

In MATLAB this is now the line I have in my startup.m file:

pe = pyenv('Version','/opt/anaconda3/envs/sci3/bin/python');

Note sci3 is the name of my environment

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.