Pyinstaller matlab-engine problem running the .exe on a different machine

조회 수: 16 (최근 30일)
Sagar Kumar
Sagar Kumar 2022년 1월 9일
답변: Grace Kepler 2024년 2월 16일
I'm working on an application that uses the matlab engine API for python. The app works fine, without any issue, therefore I wanted to pack it into a single exe.
At first I had an issue given by mlarray, that I solved by compiling with:
pyinstaller --additional-hook-dir=hooks --onefile main.py
Now on my own computer the .exe file works fine, but as soon as I try to run it on a different machine (with Matlab installed), it gives me the following error:
Traceback (most recent call last):
File "matlab\engine\__init__.py", line 45, in <module>
File "importlib\__init__.py", line 127, in import_module
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'matlabengineforpython3_8'
During handling of the above exception, another exception occurred:
'Traceback (most recent call last):
File "matlab\engine\__init__.py", line 67, in <module>
File "os.py", line 1109, in add_dll_directory
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'F:\\Matlab\\extern\\engines\\python\\..\\..\\..\\bin\\win64'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 17, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "matlab\engine\__init__.py", line 70, in <module>
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: [WinError 3] The system cannot find the path specified: 'F:\\Matlab\\extern\\engines\\python\\..\\..\\..\\bin\\win64'
[10656] Failed to execute script 'main' due to unhandled exception!
It seems that it can't find the module "matlabengineforpython3_8", which in theory is in the engine folder in the matlab installation path. Then it's looking for a file in the wrong place, because the machine doesn't have an F: disk, but my computer does.
  댓글 수: 1
Christopher Wunder
Christopher Wunder 2022년 4월 7일
This is because in matlab\engine\__init__.py it looks for the matlabengineforpython3_8 in the directories specified in _arch.txt (this file should be in the matlab\engine directory) and there are several directories from your computer hardcoded probably from when you installed matlab engine. You could try to manipulate the init file or arch.txt.
You might want to try packaging the matlab functions and scripts by using the PythonPackage functionality from Matlab Compiler SDK, but then you need this toolbox. The packages can then be installed as normal python packages and you don't call the matlab engine anymore but rather use "python import style". The other machine still needs to have matlab installed or at least matlab runtime.

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

답변 (1개)

Grace Kepler
Grace Kepler 2024년 2월 16일

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by