Unable to resolve the name 'py.anything' when using Homebrew Python

17 views (last 30 days)
I'm on an Apple Silicon mac, and the default python3 that Matlab finds (in /Library/Developer/CommandLineTools/usr/bin/python3, found with the setting pyenv('Version', 'python3')) is problematic because its pip can't seem to install numpy. The version that comes with Homebrew can build everything just fine, so I tried
>> pyenv('Version','/opt/homebrew/bin/python3')
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/opt/homebrew/opt/python@3.9/bin/python3.9"
Library: "/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9"
Status: NotLoaded
ExecutionMode: InProcess
but now, I can't access anything through py: it just says "Unable to resolve the name", making it unusable.
>> py.None
Unable to resolve the name 'py.None'.
Any ideas on why this is, or how to work around it? Perhaps something like the homebrew Python is ARM-native code (I don't know if that's the case though), and there's some kind of linking issue because Matlab is on Rosetta?
  4 Comments
井上 純
井上 純 on 30 Jul 2022
In case anyone else runs in to the same issue: I contacted Tech Support over this and it seems this is a Rosetta - ARM native linking problem. Apparently the only solution is to either compile x86-64 numpy over Rosetta (couldn't figure out how) or to wait for an ARM native Matlab to appear...
Julien Montant
Julien Montant on 24 Oct 2022
I have exactly the same issue with macports' python3.9. However, the Matlab-python binding works indeed with the "native" (command line tools) macos python3 (3.9).
What I don't understand is that if it's related with the ARM native linking, the native macOS python shouldn't work neither right?
(Waiting for the R2022b ARM compatible beta to come out, let's see how it goes...)

Sign in to comment.

Answers (2)

Al Danial
Al Danial on 27 Jul 2022
I won't have a macOS machine handy for a while so I can't experiment. I imagine the MathWorks tech support would know... unless this level of fiddling falls outside the realm of what users ought to be doing.

Nate
Nate on 12 Oct 2022
I ran into this same issue this morning. After a lot of trial and error, here is a solution that worked for me:
First, you need to have a second version of homebrew for installing intel-based apps: https://medium.com/mkdir-awesome/how-to-install-x86-64-homebrew-packages-on-apple-m1-macbook-54ba295230f
If you follow those instructions, you'll get to a point where you have added these lines to your .zsh profile:
export PATH=$HOME/bin:/usr/local/bin:$PATH# for intel x86_64 brew
alias axbrew='arch -x86_64 /usr/local/homebrew/bin/brew'
You can then use axbrew to install the x86_64 version of python3.9:
axbrew install python@3.9
After installation, i ran
axbrew unlink python@3.9
to be sure this version wasn't going to be accidently called by other programs
You should now have x86_64 versions of pip3.9 and python3.9 executables in: /usr/local/homebrew/Cellar/python@3.9/3.9.15/bin
You can use that pip3.9 to install numpy and other packages.
Then in matlab:
pyenv('Version','/usr/local/homebrew/Cellar/python@3.9/3.9.15/bin/python3.9');

Tags

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!