How do I resolve the error "ModuleNotFoundError: No module named 'matlabeng​​ineforpyt​h​on3_X'"?

조회 수: 40 (최근 30일)
I am currently setting up MATLAB Engine for Python 3.X. I used the standard setup process that is described in the documentation page on installing MATLAB Engine API for Python.
When I try to import the module "matlab.engine" in Python, I get the following error:
ModuleNotFoundError: No module named 'matlabengineforpython3_X'
The error also indicates that it is searching for the module in the directory
C:\Users\username\AppData\Local\Programs\Python\Python3X\lib\matlab\engine
instead of the directory
C:\Users\username\AppData\Local\Programs\Python\Python3X\Lib\site-packages\matlab\engine
which is where it appears that everything was installed.
How do I resolve this issue?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2026년 1월 12일 0:00
편집: MathWorks Support Team 2026년 1월 12일 21:11
This error usually indicates that the folder where MATLAB Engine is installed is not on the Python path. Follow these steps to fix this issue.
1) Find the location of the "matlab" folder, where MATLAB Engine is installed. This location can vary with different Python versions. In this case, the path is:
C:\Users\username\AppData\Local\Programs\Python\Python3X\Lib\site-packages\matlab
Note that if you installed MATLAB Engine in a non-default location using the option
install --prefix="installdir"
then the "matlab" folder will be in a subdirectory of "installdir".
2) Update to the Python path to include the parent folder of the installed "matlab" folder using one of the following methods:
Windows terminal
Using the example location noted above, run:
set PYTHONPATH=C:\Users\username\AppData\Local\Programs\Python\Python3X\Lib\site-packages;%PYTHONPATH%
Run your Python workflow from the same terminal where you added the path information.
Or add path information directly in Python as follows: 
import sys;
sys.path.append(r"C:\Users\username\AppData\Local\Programs\Python\Python3X\Lib\site-packages")
Linux/macOS terminal
From a bash terminal where the Python code will be run, enter the following: 
export PYTHONPATH=<path to matlab parent folder>:$PYTHONPATH
Run your Python workflow from the same terminal where you added the path information.
Or add path information directly in Python: 
import sys;
sys.path.append("<path to matlab parent folder")
For more information on this error message with virtual environments or when installing MATLAB Engine in a non-default location, see the following Answers post on Python failing to import MATLAB Engine in a virtual environment.
 

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by