如何在 Google-Colab 'permanent' 中升级到 python 软件包?

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

我一直在为某个数据科学项目制作笔记本,但在导入更新包时遇到了这个问题。我正在使用 matplotlib 绘图。每次我打开笔记本,Google Colab 导入版本 3.2.2.

import matplotlib
matplotlib.__version__ ## returns 3.2.2

显然,我尝试使用 !pip install matplotlib --upgrade 更新包,并且效果很好。重新启动运行时后,我现在有了更新版本的 matplotlib (3.5.1)。但是每当会话终止时,我在使用的绘图上再次出现错误,因为 matplotlib 的版本已恢复为 2.2.2。我尝试按照 中的建议使用 !pip3,但我仍然遇到同样的问题。如何在 Google Colab 中永久升级软件包?

几经搜索,默认情况下似乎没有办法做到这一点。正如 Google Colaboratory 的 FAQs 所述:

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.

不过,这个 article 值得一试。我暂时继续安装。