Not able to access Python from MATLAB on Apple silicon

I referred this page https://in.mathworks.com/matlabcentral/answers/1977529-how-to-use-python-from-matlab-on-mac-with-apple-silicon?s_tid=mwa_osa_a, and executed the command "arch -x86_64 python3 -m pip myPythonPackage" from my python virtual environment, and thought that it would resolve my problem of not able to access "py.sys.path", but it didn't help. I get the following error:
Python commands require a supported version of CPython. See Getting Started with Python.
My Python environement is given as below when printed from within MATLAB:
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/<user-name>/venv/bin/python"
Library: "/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib"
Home: "/Users/<user-name>/venv"
Status: NotLoaded
ExecutionMode: InProcess
Note that executing "arch -x86_64 python3 -m pip myPythonPackage" resulted the following error:
arch: posix_spawnp: python3: Bad CPU type in executable
My MATLAB verison is 2021b on Apple M1 Pro
Any help will be highly appreciated.

댓글 수: 1

Somnath Mukherjee
Somnath Mukherjee 2024년 4월 19일
이동: Walter Roberson 2024년 4월 19일
Hi,
Can someone please respond to this query?
Regards,
Somnath

댓글을 달려면 로그인하십시오.

답변 (1개)

Karanjot
Karanjot 2024년 3월 23일
Hi Somnath,
Do you have the Rosetta 2 translation layer for Apple Silicon macs installed?
If you haven't been prompted for any other app already, manually install Rosetta 2:
softwareupdate --install-rosetta
Adittionally, If this doesn't resolve your issue, I recommend running the following command & inspecting the results.
which -a python
Multiple python installations could be causing this error as well, if the wrong one is being invoked.
Do note that only certain python versions are supported for MATLAB R2021b. You may check the supported versions at the webpage below:

댓글 수: 3

Hi,
I tried your suggestion and please see the result below.
<python-virtual-env>$ softwareupdate --install-rosetta
I have read and agree to the terms of the software license agreement. A list of Apple SLAs may be found here: https://www.apple.com/legal/sla/
Type A and press return to agree: A
2024-04-10 20:26:59.033 softwareupdate[31850:3288130] Package Authoring Error: 052-77538: Package reference com.apple.pkg.RosettaUpdateAuto is missing installKBytes attribute
Install of Rosetta 2 finished successfully
I get a package authoring error when I run the above command.
Regardign the python verison, as you can see in my previous message, it's 3.9. And as per the page here , it's supported on 2021b.
Regards,
Somnath
Karanjot
Karanjot 2024년 4월 25일
편집: Karanjot 2024년 4월 25일
Hi,
This seems to be an issue with Rosetta / Apple. Although, Rosetta installation was completed sucessfully as the next line suggests that.
Ok. So, do you have any further recoomendations on what should be done next?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

질문:

2024년 3월 23일

댓글:

2024년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by