Calling python modules gives ModuleNotFoundError.

43 ビュー (過去 30 日間)
James Kondash
James Kondash 2022 年 4 月 1 日
コメント済み: xing quan 2024 年 2 月 2 日
I have inherited some MATLAB code which calls some python scripts (authored by the same person, but they are no longer with the organization). I am wondering if the error I am getting is due to some missing dependencies and/or files/directories? Upon executing the script I get the following errors:
Error using <frozen importlib>_find_and_load_unlocked (line 973)
Python Error: ModuleNotFoundError: No module named 'theta_controller'
Error in <frozen importlib>_find_and_load (line 991)
Error in <frozen importlib>_gcd_import (line 1014)
I put the theta_controller.py in the same folder as the main MATLAB script doing the calling.
Are there any obvious steps I have missed so python scripts can be called by MATLAB?
I am a beginner in using MATLAB, Python, and MacOS so any help would be appreciated.
  3 件のコメント
James Kondash
James Kondash 2022 年 4 月 18 日
I believe the script calls the python module as follows:
theta = py.importlib.import_module('theta_controller');
The theta_controller.py file is in the same directory as the parent MATLAB script I am trying to run.
Maybe I'm missing some dependencies, environments, and/or path specifications?
xing quan
xing quan 2024 年 2 月 2 日
I got the same error. How to solve it? Thanks!

サインインしてコメントする。

回答 (1 件)

Al Danial
Al Danial 2022 年 4 月 21 日
Does the MATLAB code change directories before calling the import command?
If you interactively invoke the import in a fresh MATLAB session as you've shown, with
>> theta = py.importlib.import_module('theta_controller')
do you also get the errors?
Will the module import correctly in Python? Open a Python session and try
import theta_controller

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by