'How do make an upgrade to a python package in Google-Colab 'permanent'?

I've been working on a notebook for some data science project, but I came across this issue with importing updated packages. I'm making plots using matplotlib. Every time I open the notebook, Google Colab imports version 3.2.2.

import matplotlib
matplotlib.__version__ ## returns 3.2.2

Obviously, I tried updating the package using !pip install matplotlib --upgrade, and this works fine. After restarting the runtime, I now have the updated version of matplotlib (3.5.1). But whenever the session terminates, I am getting errors again on the plots I use because matplotlib's version is reverted back to 2.2.2. I tried using !pip3 as suggested in this StackOverflow question, but I still get the same problem. How do I permanently upgrade a package in Google Colab?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source