Pyinstaller matlab-engine problem running the .exe on a different machine
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
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 comentario
Christopher Wunder
el 7 de Abr. de 2022
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.
Respuestas (1)
Grace Kepler
el 16 de Feb. de 2024
See this MATLAB Answers post: How to package MATLAB Engine API for Python with PyInstaller.
0 comentarios
Ver también
Categorías
Más información sobre Call MATLAB from Python en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!