gpt4 book ai didi

google-colaboratory - 如何更新 Google Colab Python 版本?

转载 作者:行者123 更新时间:2023-12-04 12:28:25 24 4
gpt4 key购买 nike

当前在 Google Colab 上运行的 Python 的默认版本是 3.7,但我的笔记本需要 3.9 才能工作。
如何将 Google Colab 的 Python 版本更新到 3.9(或更高版本)?

最佳答案

在 Google Colab 中,你有一个基于 Debian 的 linux,你可以在 Debian Linux 上做任何你能做的事情。升级 Python 就像在自己的 linux 系统中升级一样简单。
在 Colab 中检测 Python 版本:

!python --version
#3.7.11
现在让我们安装并升级到 Python 3.9:
#install python 3.9
!sudo apt-get update -y
!sudo apt-get install python3.9

#change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2

#check python version
!python --version
#3.9.6
请注意,重新启动内核后所有更改都将丢失。每个运行时都会为您提供一个全新的 google colab。
另请注意,您可以使用以下命令查看已安装的 Python 版本列表并随时在它们之间切换:
(使用此命令手动选择python版本,如果安装后没有任何变化)
!sudo update-alternatives --config python3
#after running, enter row number of python version you want.

关于google-colaboratory - 如何更新 Google Colab Python 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68657341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com