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

47 ビュー (過去 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 Center および File ExchangeCall 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