Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode and Jupyter notebook - changes in python script code dont update

When I write a code in the editor in VScode and then I try to import this code into jupyter notebook, the alterations I made in the code are do not update - the code that runs in jupyter notebook is the code that is open when I initialize VScode.

To update the code I need to restart VScode, open jupyter notebook, and import the code with the alterations made before restarting VScode. I set the path to the folder, and I using the same virtual environment. Is there anyway to fix this?

my screen

like image 792
Atilio Avatar asked Nov 28 '25 18:11

Atilio


2 Answers

Try the autoreload magic method. Above the import statement put this.

%load_ext autoreload
%autoreload 2

Note that %autoreload 2 means that all modules will be reimported, if you want to specify which ones to reload then use %autoreload 1 and import using %aimport instead of import

like image 61
RustyPython Avatar answered Nov 30 '25 10:11

RustyPython


if you are using VScode there is an easy way to restart your Jupyter Kernel. click the next buttons: enter image description here

like image 27
Ygl Avatar answered Nov 30 '25 08:11

Ygl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!