简体   繁体   中英

Remove imported package from Jupyter Notebook without restarting the kernel

Is there a way to un-import a package from Jupyter Notebook without restarting the kernel?

Why I Ask: I have a model that takes a long time to train. I am plotting some of the output of this model and when I imported seaborn it caused problems with the some of my plots. I would like to un-import seaborn without restarting the kernel and retraining the model.

I know there are workarounds like pickling the model and then replotting, but this situation got me curious about un-importing a package in Jupyter. Is that possible at all?

I assume you want to restore the defaults of the rcParameters of matplotlib, rather than unimport another module. Even if you could unimport it, the plotting parameters would remain changed.

plt.rcdefaults()

When using seaborn version 0.8, it should not interfere with your plots.

When using seaborn version 0.7 or below, you may import seaborn.apionly instead of import seaborn for the same effect. If you already have import ed seaborn see @philippd's answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM