python reload() function matlab 2014b
17 次查看(过去 30 天)
显示 更早的评论
I'm trying to use the python reload() method to reload my an edited python class that I've placed in "myfile.py"
After I first create the object and test it in matlab, changes to the .py file aren't seen. The python IDE has the same issue and one needs to call the built in method reload() - but its unclear what argument to provide it from matlab.
start with creating the object myobj in file myfile.py obj = py.myfile.myobj() then I edit "myfile.py" and need to reload it for the changes to be seen.
py.reload(????)
0 个评论
采纳的回答
uri merhav
2015-1-6
From the matlab docs under features not supported:
Editing and reloading a Python® module in the same MATLAB session. To use an updated module, restart MATLAB.
A very weird limitation at that, I know. I tried working around it but to no avail...
1 个评论
Robert Snoeberger
2015-10-6
The ability to reload edited Python code is available in R2015b. See the item "MATLAB Interface to Python: Clear Python class definitions with clear classes command, useful when reloading revised Python classes" under Advanced Software Development in the R2015b release notes [1].
更多回答(3 个)
Raghav Paul
2015-9-4
This functionality has been incorporated in R2015b using the MATLAB 'clear' command and Python 'import_module' and 'reload' commands. For an example, refer to the link below:
0 个评论
Chuck37
2015-2-23
Not being able to reload edited python is a real drag. I hope they fix this soon. Restarting matlab takes too long to fit into a debug loop.
5 个评论
Justin Mai
2019-12-5
it still does not work. followed all steps:
>> clear classes
>> VectorFuncs = py.importlib.import_module('VectorImportFunctions');
>> py.importlib.reload(VectorFuncs);
>> filesVector = cell(py.VectorImportFunctions.get_vector_files_list());
which throws an error about syntax in my code -- which I know I fixed because I added something in upper lines which definitely should fail as a syntax error in python, but isn't reflected as failing in matlab.
The only thing that works is to restart MATLAB, unfortunately. This doesn't even happen all the time; sometimes the relaod process works (even though it's still incredibly silly of a process in my ignorant opinion).
Thoughts? Thanks.
Blake Lundstrom
2021-4-7
编辑:Blake Lundstrom
2021-4-7
In R2020a (and likely everything after R2015b), the ability to reload python code does appear to work, but there is a caveat: the python code directly in the module being imported (VectorImportFunctions.py in Justin's example) DOES get reloaded, but any code that that module imports will not be reloaded until MATLAB is restarted (e.g., VectorImportFunctions.py has from X import Y in it, the code in X will not be reloaded until a restart). A work-around to this is to also reload the module being imported (so import and reload X in MATLAB in this example, even though it isn't strictly necessary to import it to MATLAB since the original python module imports it). This worked for me when using in-process python execution (the default).
For what it is worth, in the process of debugging this issue, I tried out-of-process execution (see https://www.mathworks.com/help/matlab/matlab_external/out-of-process-execution-of-python-functionality.html), since there were examples for reloading the process. However, MATLAB (R2020a, Win10) just crashes right before execution of my code every time I try to use the out-of-process option (even when running MATLAB as admin), so not recommended (beyond the fact that Mathworks indicates out-of-process adds overhead).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!