필터 지우기
필터 지우기

OSError: MATLAB Engine for Python 3.8 on MacBook Pro with M1 chip

조회 수: 35 (최근 30일)
Mehul Garg
Mehul Garg 2021년 1월 25일
답변: alaa Ahmed 2022년 5월 31일
After running the setup.py file I am trying to import the MATLAB engine from python and i get an OSError:
Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: dlopen(/Applications/MATLAB_R2020b.app/extern/engines/python/dist/matlab/engine/maci64/matlabengineforpython3_8.so, 2): no suitable image found. Did find:
/Applications/MATLAB_R2020b.app/extern/engines/python/dist/matlab/engine/maci64/matlabengineforpython3_8.so: mach-o, but wrong architecture
/Applications/MATLAB_R2020b.app/extern/engines/python/dist/matlab/engine/maci64/matlabengineforpython3_8.so: mach-o, but wrong architecture
I have run the usual command:
import matlab.engine
I have MATLAB 2020b latest version running smoothly via rosetta on the said machine. Aren't the MATLAB python engine libraries updated to handle the same.
Kindly help me circumvent this problem.
  댓글 수: 2
Peter Somhorst
Peter Somhorst 2021년 10월 21일
편집: Peter Somhorst 2021년 10월 21일
Hi Mehul,
How did you install Python? I found it doesn't work if you install it through pyenv. What worked for me (installing it, haven't tested anything yet):
  • install python 3.8 through homebrew (`arch -x86_64 /usr/local/bin/brew install python@3.8`)
  • install the matlab engine in this version of python (`/usr/local/opt/python@3.8/bin/python3.8 setup.py install`)
NB: Matlab 2021B supports Python 3.9 as well.
Hope this helps!
xenon zhang
xenon zhang 2021년 11월 1일
hello, you can use
arch -x86_64 python3
instand of
python3
in terminal to run python as a x86 program (without install another version), then matlab engine can working well

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

답변 (2개)

alaa Ahmed
alaa Ahmed 2022년 5월 31일
If you are running matlab in Macbook pro with MATLAB 2020b .. Please run this command on matlab command window so that you set the python evironment directory
pyversion /usr/local/bin/python3
Then type pyenv, you will be able to find all PythonEnvironment feilds are filled :D
pyenv
ans =
PythonEnvironment with properties:
Version: "3.8"
Executable: "/usr/local/bin/python3"
Library: "/Library/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib"
Home: "/Library/Frameworks/Python.framework/Versions/3.8"
Status: NotLoaded
ExecutionMode: OutOfProcess

Rashed Mohammed
Rashed Mohammed 2021년 1월 28일
Hi Mehul,
Since you are trying to load matlab engine (which is x86_64) from python3, It is necessary to run python3 also under rosetta2. I was able to reproduce your issue and running python3 under rosetta2 fixed the issue.
Hope this helps!
  댓글 수: 2
Hyung-Chun Lee
Hyung-Chun Lee 2021년 8월 30일
I have tried it many times but I could not succeed.
xenon zhang
xenon zhang 2021년 11월 1일
@Hyung-Chun Lee you can try
arch -x86_64 python3
to run your script, for example
arch -x86_64 python3 test.py
instand of
python3 test.py
it work for me

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

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by