Matlab sees old version of python module -- how do I refresh Matlab's view of python files/modules imported by a python file called on by pyrunfile?

15 ビュー (過去 30 日間)
I have a Matlab file that uses pyrunfile() to run a python file. That python file imports a module from another file that I edit frequently. However, in order for the saved changes that I make in the python module file to be used, I have to close out of matlab and restart it. Otherwise an older (seemingly non-existant) version of the python module file gets used. Is there a way that I can refresh matlab (without closing out) so that when my python file imports the module, it imports the up-to-date version of the module?

回答 (1 件)

Ethan Williams
Ethan Williams 2022 年 11 月 4 日
Well, I found a workaround based on a similar question.
In my case, however, I am using pyrunfile and don't need to keep the module in Matlab's workspace. Reloading it in Matlab seems to solve the problem, then I just remove the module. My fix is this:
Foo = py.importlib.reload(py.importlib.import_module('Opx_Config'));
clear Foo
  2 件のコメント
Ethan Williams
Ethan Williams 2022 年 11 月 4 日
Would still be interested to see if anyone has a cleaner, more general way of doing this with one function.
Emerick
Emerick 2025 年 4 月 11 日
編集済み: Emerick 2025 年 4 月 11 日
Same problem here (but using my own modules), so far I'm stuck and your fix doesn't seem to work for me (thanks for trying to help though)

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

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by