Fail to start matlab engine in python 2022b

102 views (last 30 days)
Jiaxin Peng
Jiaxin Peng on 25 Sep 2022
Answered: Hajar on 9 Jan 2023 at 3:17
I use MacBook Pro M1 chip with macOS13 and Python version is 3.9.13.
I installed the Matlab R2022b and followed the document to install engine API via pip with code :
python -m pip install matlabengine
However, when I call matlab engine, it is failed with the output
raise RuntimeError("Could not find directory: {0}".format(engine_dir))
RuntimeError: Could not find directory: /Applications/MATLAB_R2022b.app/extern/engines/python/dist/matlab/engine/maca64
I find the directory that I can only find maci64.
May I know how could I start matlab.engine in Python?
  1 Comment
Praveen C
Praveen C on 2 Dec 2022
Why does matlab make it so hard to use jupyter. It is as if they dont want us using matlab with jupyter.

Sign in to comment.

Answers (4)

Jonathan Lilly
Jonathan Lilly on 30 Oct 2022
I have the same issue. Perhaps an M1 chip issue?

Charles King
Charles King on 1 Dec 2022
I think it is a M1 chip issue because I have the following directory: /Applications/MATLAB_R2022b.app/extern/engines/python/dist/matlab/engine/maci64
and
/Applications/MATLAB_R2022b.app/extern/engines/python/dist/matlab/engine/maca64
is what the script is looking for.

Kannan
Kannan on 28 Sep 2022
Could you check the default install location of MATLAB? This can be done by going into the MATLAB Command Window and calling :
matlabroot
By default, you will find MATLAB installed at the following location
/Applications/MATLAB_R2022b.app
When MATLAB is not installed in the default location, the bin/architecture directory within the MATLAB root directory must be added to an environment variable. The path can be added to the environment variable within the shell startup configuration file:
# in .bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<matlabroot>/bin/glnxa64
Could you try these steps to see if the error still persists?
  5 Comments
Jiaxin Peng
Jiaxin Peng on 1 Jan 2023 at 15:44
Edited: Jiaxin Peng on 1 Jan 2023 at 15:46
Hi all,
I can installed matlabengine now. However, I faced another issue:
import matlab.engine
>>> eng = matlab.engine.start_matlab()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/matlab/engine/__init__.py", line 130, in start_matlab
eng = future.result()
File "/usr/local/lib/python3.10/site-packages/matlab/engine/futureresult.py", line 67, in result
return self.__future.result(timeout)
File "/usr/local/lib/python3.10/site-packages/matlab/engine/matlabfuture.py", line 87, in result
handle = pythonengine.getMATLAB(self._future)
matlab.engine.EngineError: Connection to process with Exchange: " " was lost.
May I know how to solve this?

Sign in to comment.


Hajar
Hajar on 9 Jan 2023 at 3:17
My MATLAB runtime root is at /usr/local/MATLAB_Runtime/R2022b on a GUI-less server Ubuntu 20.04 installation, so I checked
echo $LD_LIBRARY_PATH
And got nothing (it's not set) - am I required to install something else before R2022b to get this to work?
Then, I set the variable:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/MATLAB_Runtime/R2022b/glnxa64
Still got the following error with pip install:
RuntimeError: MATLAB R2022b installation not found. Install to default location, or add <matlabroot>/bin/glnxa64 to LD_LIBRARY_PATH, where <matlabroot> is the root of a MATLAB R2022b installation.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!