在 Google Colaboratory 中安装 Python 3.8 内核 [英] Install Python 3.8 kernel in Google Colaboratory

查看:83
本文介绍了在 Google Colaboratory 中安装 Python 3.8 内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 conda 安装新的 Python 版本 (3.8).

I try to install a new Python version (3.8) using conda.

!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh
!chmod +x mini.sh
!bash ./mini.sh -b -f -p /usr/local

这很好用.我可以调用 !python script.py 来运行 3.8 版本.

This works fine. I can call !python script.py to run a 3.8 version.

因此,我尝试使用 Python 3.8 内核安装另一个 jupyter 内核.

So, I try my luck with installing another jupyter kernel with Python 3.8 kernel.

!conda install -q -y --prefix /usr/local jupyter
!python -m ipykernel install --name "py38" --user

我检查内核是否已安装.

I check that the kernel is installed.

!jupyter kernelspec list

然后我将笔记本下载下来.打开文本编辑器将内核规范更改为

Then I download the notebook down. Open a text editor to change the kernel specification to

"kernelspec": {
  "name": "py38",
  "display_name": "Python 3.8"
}

这与之前使用 Javascript、Java 和 Golang 的技巧相同.

This is the same trick that works before, with Javascript, Java, and Golang.

然后我将编辑后的笔记本上传到 Google Drive.在 Google Colab 中打开笔记本.它找不到py38内核,所以它使用普通的python3内核.我再次运行所有这些单元格.

I then upload the edited notebook to Google Drive. Open the notebook in Google Colab. It cannot find the py38 kernel, so it use normal python3 kernel. I run all these cell again.

!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh
!chmod +x mini.sh
!bash ./mini.sh -b -f -p /usr/local
!conda install -q -y --prefix /usr/local jupyter
!python -m ipykernel install --name "py38" --user

它像以前一样安装 Python 3.8 内核.我刷新浏览器,让它连接到新内核,希望它像以前的JavaScript、Java、Golang内核一样工作.

It install the Python 3.8 kernel like before. I refresh the browser, to let it connect to the new kernel, hoping it to work like JavaScript, Java, Golang kernel before.

它不起作用.它无法连接.这是笔记本

It doesn't work. It cannot connect. Here's the notebook

任何帮助将不胜感激.

推荐答案

我已经找到了如何在 Colab 上运行 Python 3.8 notebook.

I have found how to run Python 3.8 notebook on Colab.

  • 安装 Anaconda3
  • 添加(假)google.colab 库
  • 启动 jupyterlab
  • 使用 ngrok 访问它

这是代码

# 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.7/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))

这篇关于在 Google Colaboratory 中安装 Python 3.8 内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆