Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 207
jsv Avatar asked Nov 16 '25 20:11

jsv


1 Answers

After several searches, there seems to be no way to do that by default. As explained from the FAQs of Google Colaboratory:

Code is executed in a virtual machine private to your account. Virtual machines are deleted when idle for a while, and have a maximum lifetime enforced by the Colab service.

This article, however, is worth a shot. I'll keep installing for now.

like image 90
jsv Avatar answered Nov 18 '25 08:11

jsv



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!