slug
tags
password
icon
lang
date
category
type
status
summary
{/* truncate */}
With the publishing of the pre-release MATLAB R2023b Apple Silicon native support, MATLAB Engine for Python can be installed via 'setup.py' script in the engine folder.
You can use the following code:
The output will be:
Then you can check whether the engine installed successfully by running the following code:
The output should be
2.0
.Following above process can help you to install the engine. However, I am not sure whether it is stable or not. You can try it by yourself. If you find any problem, you can try to contact MATLAB support team.
Issues with MATLAB Engine on Apple Silicon
Since I switched to appli silicon and installed MATLAB R2022a and R2022b, MATLAB Engine for Python is invalid.
To solve the issue, we need to install Python via
arch-x86_64
. Before that, I assume you have already installed native homebrew
and set up well.Install Homebrew via x86_64
platform
- Install
homebrew
viaarch-x86_64
platform
- Add
arch-x86_64
toPATH
in~/.zshrc
. byopen ~/.zshrc
and add the following line to the end of the file.
The
brow
is the alias for brew
and ib
is the alias for arch-x86_64
.- Add an alias to switch between
arch-x86_64
andarch-arm64
platform
Install Python via x86_64
platform
- Install python via
arch-x86_64
platformhomebrew
.
Wait for the installation.
Install MATLAB Engine for Python
- Install
MATLAB Engine for Python
.
Start from R2022b, you can install matlab engine via
pip
.- Test the installation.
Wait for the starting of the MATLAB engine.
Warning:
In this step, you may have an error return:
Until now, I did not find any solution to solve this issue if running all code in Terminal.
Run MATLAB Engine for Python in Pycharm
However, I find that I can use MATLAB Engine in Pycharm by virtual environment.
First, you need to create a virtual environment in Pycharm with
x86_64
platform Python3
.
Then, update all packages including
pip
in the virtual environment.
You should have matlabengine installed in the virtual environment since you did it in the previous step.Finally, you can import
matlab.engine
and test it in Pycharm with Python Console.The output should return
5
.- Author:PENG Jiaxin
- URL:https://www.pengjiaxin.com/article/matlabengine-python
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!