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

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