Skip to content

Instantly share code, notes, and snippets.

@MohamedElashri
Last active February 26, 2022 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MohamedElashri/dab00a84ba6a65f99fb2694504ecc39e to your computer and use it in GitHub Desktop.
Save MohamedElashri/dab00a84ba6a65f99fb2694504ecc39e to your computer and use it in GitHub Desktop.
This is the way to install ROOT CERN in Google Colab,.
# This code is for installing ROOT on Google Colab to be able to install root_numpy and root_pandas package later
# for version of this code which work with python3 visit
#https://gist.github.com/MohamedElashri/1b0367992988f053a02dbfd5797fb59e
!mkdir -p APPS
!pwd
!cd APPS && wget https://root.cern.ch/download/root_v6.13.08.Linux-ubuntu18-x86_64-gcc7.3.tar.gz
!cd APPS && tar -xf root_v6.13.08.Linux-ubuntu18-x86_64-gcc7.3.tar.gz
import sys
sys.path.append("/content/APPS/root/lib")
import ctypes
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libMultiProc.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libCore.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libThread.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libImt.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libRIO.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libNet.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libGraf3d.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libTreePlayer.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libMultiProc.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libTree.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libMathCore.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libMatrix.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libHist.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libGraf.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()
@davitjnz
Copy link

davitjnz commented Feb 4, 2021

I am getting the error:

'OSError: libNet.so: cannot open shared object file: No such file or directory'

@MohamedElashri
Copy link
Author

Not sure what is wrong about your runtime. This is a Colab notebook that I've used this code into and works.
You can make a copy and try to work from this notebook.
https://colab.research.google.com/drive/1p-hlKAsBXvMCR1BzZ-SXEhxJ0xiywUtA?usp=sharing

@MohamedElashri
Copy link
Author

I think the problem is that libNet.so is decrypted in python 3, so you have to use python 1.
This is actually a problem with pyroot and similar tools that they have not been complied for python 3.

Unfortunately also google colab decrypted python 2 also, and you can't choose it as a runtime for new notebooks. Instead, you can use mine.

@MohamedElashri
Copy link
Author

I have updated the code to make it work with python 3
https://gist.github.com/MohamedElashri/1b0367992988f053a02dbfd5797fb59e

So it will work now on colab as they stopped supporting python 2 completely.

@gmazzitelli
Copy link

dear mohamed,
thank you for your job, very useful... although I hope that soon or later someone succeed to make a clean installation
did you been able to open TWeb file?
Error in TWebFile::TWebFile: https://s.../histograms_Run03965.root? does not exist
I think some path is still missing

@MohamedElashri
Copy link
Author

MohamedElashri commented May 4, 2021

dear mohamed,
thank you for your job, very useful... although I hope that soon or later someone succeed to make a clean installation
did you been able to open TWeb file?
Error in TWebFile::TWebFile: https://s.../histograms_Run03965.root? does not exist
I think some path is still missing

Hi Giovanni

This method shouldn't work anymore because it doesn't work with Python 3 and colab stopped python 2 support.
You can try the new one I explained in another gist here.
https://gist.github.com/MohamedElashri/1b0367992988f053a02dbfd5797fb59e

If you are referring to this new version and have a problem with TWeb files I didn't use it before. However, I have some idea how to use it . TWebFile is using http protocoal which is implemented in libNet. I think you need to add this line with other lib paths.

ctypes.cdll.LoadLibrary('/content/root_build/lib//libNet.so')

Let me know if this works.

Hint: you might need to build libNet manually and mount it to the path. You can see the build instructions in the main project README.md
https://github.com/libnet/libnet

@gmazzitelli
Copy link

gmazzitelli commented May 4, 2021

Hi

dear mohamed,
thank you for your job, very useful... although I hope that soon or later someone succeed to make a clean installation
did you been able to open TWeb file?
Error in TWebFile::TWebFile: https://s.../histograms_Run03965.root? does not exist
I think some path is still missing

Hi Giovanni

This method shouldn't work anymore because it doesn't work with Python 3 and colab stopped python 2 support.
You can try the new one I explained in another gist here.
https://gist.github.com/MohamedElashri/1b0367992988f053a02dbfd5797fb59e

If you are referring to this new version and have a problem with TWeb files I didn't use it before. However, I have some idea how to use it . TWebFile is using http protocoal which is implemented in libNet. I think you need to add this line with other lib paths.

ctypes.cdll.LoadLibrary('/content/root_build/lib//libNet.so')

Let me know if this works.

Hint: you might need to build libNet manually and mount it to the path. You can see the build instructions in the main project README.md
https://github.com/libnet/libnet

Thanks, yes I'm using your compiled distribution of root but acutely I loaded "brutally" all the lib with the following code
libfile = !ls /content/root_build/lib/.so
for i, lib in enumerate(libfile):
if not (lib=='/content/root_build/lib/libtbbmalloc_proxy.so' or lib=='/content/root_build/lib/libtbbmalloc.so' or lib=='/content/root_build/lib/libtbb.so'):
ctypes.cdll.LoadLibrary(lib)
without success.... looks to be a problem of "plugin" but I'm not so expert of root to understand the error
ps in colab py2 script it works perfectly and the file are accessible without any password.

@MohamedElashri
Copy link
Author

Hi

dear mohamed,
thank you for your job, very useful... although I hope that soon or later someone succeed to make a clean installation
did you been able to open TWeb file?
Error in TWebFile::TWebFile: https://s.../histograms_Run03965.root? does not exist
I think some path is still missing

Hi Giovanni
This method shouldn't work anymore because it doesn't work with Python 3 and colab stopped python 2 support.
You can try the new one I explained in another gist here.
https://gist.github.com/MohamedElashri/1b0367992988f053a02dbfd5797fb59e
If you are referring to this new version and have a problem with TWeb files I didn't use it before. However, I have some idea how to use it . TWebFile is using http protocoal which is implemented in libNet. I think you need to add this line with other lib paths.
ctypes.cdll.LoadLibrary('/content/root_build/lib//libNet.so')
Let me know if this works.
Hint: you might need to build libNet manually and mount it to the path. You can see the build instructions in the main project README.md
https://github.com/libnet/libnet

Thanks, yes I'm using your compiled distribution of root but acutely I loaded "brutally" all the lib with the following code
libfile = !ls /content/root_build/lib/.so
for i, lib in enumerate(libfile):
if not (lib=='/content/root_build/lib/libtbbmalloc_proxy.so' or lib=='/content/root_build/lib/libtbbmalloc.so' or lib=='/content/root_build/lib/libtbb.so'):
ctypes.cdll.LoadLibrary(lib)
without success.... looks to be a problem of "plugin" but I'm not so expert of root to understand the error
ps in colab py2 script it works perfectly and the file are accessible without any password.

Can you give me example of the code (particularly example file) that you are trying to run so that I can do some debugging?

@gmazzitelli
Copy link

Hi

dear mohamed,
thank you for your job, very useful... although I hope that soon or later someone succeed to make a clean installation
did you been able to open TWeb file?
Error in TWebFile::TWebFile: https://s.../histograms_Run03965.root? does not exist
I think some path is still missing

Hi Giovanni
This method shouldn't work anymore because it doesn't work with Python 3 and colab stopped python 2 support.
You can try the new one I explained in another gist here.
https://gist.github.com/MohamedElashri/1b0367992988f053a02dbfd5797fb59e
If you are referring to this new version and have a problem with TWeb files I didn't use it before. However, I have some idea how to use it . TWebFile is using http protocoal which is implemented in libNet. I think you need to add this line with other lib paths.
ctypes.cdll.LoadLibrary('/content/root_build/lib//libNet.so')
Let me know if this works.
Hint: you might need to build libNet manually and mount it to the path. You can see the build instructions in the main project README.md
https://github.com/libnet/libnet

Thanks, yes I'm using your compiled distribution of root but acutely I loaded "brutally" all the lib with the following code
libfile = !ls /content/root_build/lib/.so
for i, lib in enumerate(libfile):
if not (lib=='/content/root_build/lib/libtbbmalloc_proxy.so' or lib=='/content/root_build/lib/libtbbmalloc.so' or lib=='/content/root_build/lib/libtbb.so'):
ctypes.cdll.LoadLibrary(lib)
without success.... looks to be a problem of "plugin" but I'm not so expert of root to understand the error
ps in colab py2 script it works perfectly and the file are accessible without any password.

Can you give me example of the code (particularly example file) that you are trying to run so that I can do some debugging?

this is an the example working on colab with py2.
https://github.com/gmazzitelli/studenti/blob/master/read_image_root_py2.ipynb
actually reading the root file https://s3.cloud.infn.it/v1/AUTH_2ebf769785574195bde2ff418deac08a/cygnus/Data/LAB/histograms_Run04020.root

@RussMarro
Copy link

Hi Mohamed,

Thank you so much for this! It worked great for me.

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