Questions & Answers

How to update a python library without restarting ipynb kernel?

Unfortunately, there is no better way to do this, so please don't ask why I can't do it the normal way, it is too long to explain :). The issue is that one of the packages demands numpy<=1.21, but the one installed is 1.23.4 . In the notebook I run !pip install numpy==1.21 which solves the issue, BUT pip tells you that to see the changes you have to restart the notebook (which I cannot do). I think that is because the notebook runs in a virtual environment and numpy is installed outside of it. I have tried many things like %%reboot or importlib.reload(np), but the output of

import numpy as np


Is strictly 1.23.4 . Maybe there is a way to overcome this?

Answers(1) :

I often use the line magics

%reload_ext autoreload
%autoreload 2

At the start of the notebook to allow for incremental development of a library. Maybe that will work on this case?