Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Python 3.8 kernel in Google Colaboratory

Tags:

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 

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

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" } 

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

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 

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

Any help would be appreciated.

like image 263
korakot Avatar asked Mar 20 '20 13:03

korakot


People also ask

How do I use specific version of Python in Google Colab?

In Colab, we can enforce the Python version by clicking Runtime -> Change Runtime Type and selecting python3 . Note that as of April 2020, Colab uses Python 3.6. 9 which should run everything without any errors.

How do I run Python code in Google Drive?

The Google Colaboratory (“Colab”) is a notebook (like a Jupyter Notebook) where you can run Python code in your Google Drive. You can write text, write code, run that code, and see the output – all in line in the same notebook. Sharing notebooks is as easy as sharing any Google document.

Can I deploy the Earth Engine Python API in a notebook?

The Earth Engine Python API can be deployed in a Google Colaboratory notebook. Colab notebooks are Jupyter notebooks that run in the cloud and are highly integrated with Google Drive, making them easy to set up, access, and share. If you are unfamiliar with Google Colab or Jupyter notebooks, please spend some time exploring the Colab welcome site.

What version of python do I need to run tools?

Some tools require Python >3.7. Python 3.8 is faster than 3.6. Python 3.6 End of full support since 2018-12-24. Ubuntu 20.04 LTS available with default Python 3.8 and will be main OS on servers for next 2 years. Python 3.8 is available in Colab.

How do I create a collaboratory in Google Drive?

Open Google Drive and create a new file. Right click in a folder and select More > Colaboratory from the context menu. Visit the Colab site and create a new file.


Video Answer


1 Answers

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

  • install Anaconda3
  • add (fake) google.colab library
  • start jupyterlab
  • access it with ngrok

Here's the code

# 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)) 
like image 185
korakot Avatar answered Sep 17 '22 12:09

korakot