Skip to content

Instantly share code, notes, and snippets.

@MohamedElashri
Last active March 20, 2025 23:01
Show Gist options
  • Save MohamedElashri/1b0367992988f053a02dbfd5797fb59e to your computer and use it in GitHub Desktop.
Save MohamedElashri/1b0367992988f053a02dbfd5797fb59e to your computer and use it in GitHub Desktop.
Run ROOT on google colab, working with python 3.11 [latest python version on Colab]. More information at https://melashri.net/ROOT
# Step 1: Download the pre-built ROOT tarball from GitHub Releases
!wget -q --show-progress https://github.com/MohamedElashri/ROOT/releases/download/v6.30.04_python11/root_v6.30.04_Ubuntu_Python3.11.zip
# Step 2: Extract the ROOT files
!unzip -q root_v6.30.04_Ubuntu_Python3.11.zip
# Step 3: Install missing system dependencies for ROOT
!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
# Step 4: Remove the tarball to free up space
!rm -f root_v6.30.04_Ubuntu_Python3.11.zip
# Step 5: Install Compatible libssl
!wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
!sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
!rm -f libssl1.1_1.1.1f-1ubuntu2_amd64.deb
import sys
sys.path.append("/content/root_build/")
sys.path.append("/content/root_build/bin/")
sys.path.append("/content/root_build/include/")
sys.path.append("/content/root_build/lib/")
import ctypes
ctypes.cdll.LoadLibrary('/content/root_build/lib//libCore.so')
ctypes.cdll.LoadLibrary('/content/root_build/lib//libThread.so')
ctypes.cdll.LoadLibrary('/content/root_build/lib//libTreePlayer.so')
import ROOT
h = ROOT.TH1F("gauss","Example histogram",100,-4,4)
h.FillRandom("gaus")
c = ROOT.TCanvas("myCanvasName","The Canvas Title",800,600)
h.Draw()
c.Draw()
@Jordan597
Copy link

Olá Mohamed. Hoje 21/02/2025, como instalar o ROOT CERN no Google Colab em colab.research.google.com ?
Desde já, obrigado !

Olá, parece que o Colab atualizou novamente a versão do Python para py3.11, então a atual não funcionará.

Eu construí o ROOT v6.30.04 para py3.11 e o carreguei para releases. Então você pode usar o exemplo neste notebook que funcionará.

Acho que vou precisar de uma maneira mais organizada e automatizada de fazer isso, que estou implementando atualmente, que não dependerá de trabalho manual. Atualizarei este gist quando terminar.

Thank you Mohamed. It is good to hear that someone wants to help us with this question!!

@Jordan597
Copy link

When I run the code it returns the following error on the line ctypes.cdll.LoadLibrary("root_build/lib/libCore.so")

OSError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.38' not found (required by root_build/lib/libCore.so)

@MohamedElashri
Copy link
Author

When I run the code it returns the following error on the line ctypes.cdll.LoadLibrary("root_build/lib/libCore.so")

OSError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.38' not found (required by root_build/lib/libCore.so)

Sorry I did this mistake. I will fix it but will take two hours until build get updated. in the mean time change the downloaded link in first cell by this zip file. Change the first line to this.

!wget -q --show-progress https://github.com/MohamedElashri/ROOT/releases/download/ubuntu/root_v6.30.04_Ubuntu_Python3.11.zip

Or just try to work from this notebook

@Jordan597
Copy link

It's working for now

@MohamedElashri
Copy link
Author

It's working for now

Great, enjoy using it and please tell if at any point it stopped working.

@Jordan597
Copy link

Captura de tela 2025-02-28 112744

@Jordan597
Copy link

When i try to import root_numpy it gives me

Captura de tela 2025-03-20 174903

Thank you!

@MohamedElashri
Copy link
Author

When i try to import root_numpy it gives me

Captura de tela 2025-03-20 174903

Thank you!

There are several problems

1- You didn't install root_numpy
2- root_numpy is not part of ROOT and is a separate software
3- It is unmaintained for years now and not will work with new python version (certainly not on Colab)

So you shouldn't use it but work with PyROOT which is the python wrapper of ROOT that this installs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment