Last active
July 20, 2023 11:08
-
-
Save MohamedElashri/1b0367992988f053a02dbfd5797fb59e to your computer and use it in GitHub Desktop.
Run ROOT on google colab, working with python 3.10 [latest python version on Colab].
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!wget https://github.com/MohamedElashri/ROOT/releases/download/ubuntu/root_v6.28.04_Ubuntu_20.04.zip | |
!unzip /content/root_v6.28.04_Ubuntu_20.04.zip | |
!apt-get install git dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev libxft-dev libxext-dev tar gfortran subversion | |
!apt-get inatall libpython3.6-dev | |
# The following is needed because colab upgraded the openssl library | |
!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 | |
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() |
Update: I built a ROOT version with python3.10 and updated the gist. You can use the method now without python3.6
virtual env trick. Example is provided here
I forgot to add that I updated the ROOT version to v6.28
instead of the old v6.14
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for bringing this to my attention, I didn't use ROOT on colab for a long time. Colab now updated runtime python to
python3.10
and does not have thepython3.6
shared libraries that this trick use. I will need to build a new version forROOT
and the libs needed. I don't have time for that but there is a workaround that should give you ROOT on colab but will probably create more problems if you depend on other packages (new version of them)We can make colab use
python3.6
which will work with the current ROOT build. There might other clever methods but this worked for me as of 4th of July 2023We will create a virtual env for python3.6 and use it instead of version that comes by default with Colab runtime
1- Install the required packages and create a virtual environment with Python 3.6:
2- Create the env
4- Install pip for Python 3.6:
This should give you something like this
6- Install the required packages inside the virtual environment:
7- Add the virtual environment as a new kernel to Jupyter:
8- run this gist code
Now you will have a ROOT working again. This is probably not the best solution, and you might see problems down the line, but the optimal solution would be to build ROOT for python3.10 and provide the pre-built (ROOT team doesn't provide python3.10 compatible pre-build version on ubuntu)
I also updated my notebook with the workaround presented here