Autoreload Python packages/modules

Hello,
is it possible to autoreload python modules (my own files.py) that I have recently modified without having to restart julia? I am using PyCall but I can change to PythonCall if needed.
This is what I am doing:

pushfirst!(PyVector(pyimport("sys")."path"), "")
stream = pyimport("stream")
potentials = pyimport("potential_classes")

I would like to know the analogue of the Python notebook commands:

%load_ext autoreload
%autoreload 2

I tried with Revise.jl but didn’t worked for this case.

Thank you very much!

I don’t know about automatically doing it, but you can manually reload modules with importlib.reload

https://docs.python.org/3/library/importlib.html#importlib.reload

1 Like

You could use FileWatching as well to trigger this on file change (with an @async loop): File Events · The Julia Language

1 Like

Thanks, this exactly what I was needing. Just to be able to reload manually without having to restart Julia session.

Thank you very much!