ROOT on Colab
python3.11
and dropped python3.10
support so the updated build method will not work. I have built ROOT
and updated the code to work with this version.python3.10
and dropped python3.6
support so the original method will not work. I have built ROOT
and updated the code to work with this version.Several months ago, I needed to use ROOT on Google Colab. I found a few suggesetions on the web, but none of them worked for me. So, I decided explore and try to make it work myself tutorial. In this article, I will show you how to install ROOT on Google Colab and how to use it in colab Jupyter notebook session.
First I did the build from source part that is completely described in the ROOT installation guide. and uploaded the ROOT folder to a github repository. Then I created a new colab notebook and added the following code to the first cell:
1
2# Step 1: Download the pre-built ROOT tarball from GitHub Releases
3!wget -q --show-progress https://github.com/MohamedElashri/ROOT/releases/download/ubuntu/root_v6.30.04_Ubuntu_Python3.11.zip
4
5
6
7# Step 2: Extract the ROOT files
8!unzip -q root_v6.30.04_Ubuntu_Python3.11.zip
9
10# Step 3: Install missing system dependencies for ROOT
11!sudo ldconfig & apt-get install -y git dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev libxft-dev libxext-dev tar gfortran subversion libpython3.11-dev
12
13# Step 4: Remove the tarball to free up space
14!rm -f root_v6.30.04_Ubuntu_Python3.11.zip
15
16# Step 5: Install Compatible libssl
17!wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
18!sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
19!rm -f libssl1.1_1.1.1f-1ubuntu2_amd64.deb
The first step is downloading the prebuild ROOT v6.30.04
from my github repository. The second step is extracting the ROOT files. The third step is installing missing system dependencies for ROOT. The fourth step is removing the zip file to free up space. The fifth step is installing Compatible libssl
.
Then you need to add ROOT to the python path and load the ROOT libraries. Add the following code to the second cell:
1import sys
2sys.path.append("/content/root_build/")
3sys.path.append("/content/root_build/bin/")
4sys.path.append("/content/root_build/include/")
5sys.path.append("/content/root_build/lib/")
6import ctypes
7ctypes.cdll.LoadLibrary('/content/root_build/lib//libCore.so')
8ctypes.cdll.LoadLibrary('/content/root_build/lib//libThread.so')
9ctypes.cdll.LoadLibrary('/content/root_build/lib//libTreePlayer.so')
The first line of this code add the ROOT folder to the python path. The second line add the bin folder to the python path. The third line add the include folder to the python path. The last line add the lib folder to the python path. Then it load the ROOT libraries.
Now we are ready to use ROOT in colab. I added the following code to the third cell as an example:
1import ROOT
2
3h = ROOT.TH1F("gauss","Example histogram",100,-4,4)
4h.FillRandom("gaus")
5c = ROOT.TCanvas("myCanvasName","The Canvas Title",800,600)
6h.Draw()
7c.Draw()
You can see the output of this code in the following image:
Also you can find example notebook on Colab here that you can use directly.