免费白嫖GoogleT4和T100——Colab 更换python版本

我们有时候根据具体任务,需要变动python版本,但Colab官方给出的解释是只有python2.7和python3.6可用,拜托,python3.9都出来啦,现在给出切换python3.8参考代码。

升级

按照以下代码一步步执行即可:

#察看当前python 版本
!python -V
# install Anaconda3
!wget -qO ac.sh https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh 
!bash ./ac.sh -b
# a fake google.colab library
!ln -s /usr/local/lib/python3.6/dist-packages/google \
       /root/anaconda3/lib/python3.8/site-packages/google
# start jupyterlab, which now has Python3 = 3.8
!nohup /root/anaconda3/bin/jupyter-lab --ip=0.0.0.0&
# access through ngrok, click the link
!pip install pyngrok -q
from pyngrok import ngrok
print(ngrok.connect(8888))
import os
os.environ['PATH'] = '/root/anaconda3/bin:' + os.environ['PATH']
#察看更新后的python 版本
!python -V

降级

最近有读者问,现在colab的版本是3.7,要如何降到3.6
现在给上具体操作
首先去官网https://repo.anaconda.com/archive/下载对应python版本的anaconda
比如下载python3.6.5的操作步骤如下

# install Anaconda3
!wget -qO ac.sh https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
!bash ./ac.sh -b
# a fake google.colab library
!ln -s /usr/local/lib/python3.7/dist-packages/google \
       /root/anaconda3/lib/python3.6/site-packages/google
# start jupyterlab, which now has Python3 = 3.6
!nohup /root/anaconda3/bin/jupyter-lab --ip=0.0.0.0&
# access through ngrok, click the link
!pip install pyngrok -q
from pyngrok import ngrok
print(ngrok.connect(8888))
import os
os.environ['PATH'] = '/root/anaconda3/bin:' + os.environ['PATH']
#察看更新后的python 版本
!python -V

参考stackoverflow:链接🔗

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页