I am interested in ways to browse and manipulate .root files with Python in a Windows environment.
In my research group, we use ROOT 5.34/36 (v5-34-36@v5-34-36, Apr 05 2016, 10:25:45 on win32) on VS to process big data. The subsequent manipulation of single final plots become very demanding using c++ and such an obsolete (aka buggy) version of ROOT. Recently, some colleagues started to export our resulting plots into ASCII format to process them with Python 3.7. My goal would be to avoid this last step, browsing into a .root file exporting TH* plots to manipulate them with Py libraries.
Do you have any suggestion? I guess it should be possible without the need of PyROOT, am I right? In this thread there were already some suggestions, but I’d like to go deeper in the subject.
Best regards,
GN
_ROOT Version: 5.34/36
_Platform: Windows 10
_Compiler: VScode / VS15
You can try with the latest version of ROOT 6 on Windows, PyROOT should come with it anyway, even if the new PyROOT will only be in the next version. And @etejedor might correct me, but I think you need PyROOT to read ROOT files with Python
>>> import ROOT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\root\6.22.02vs19_aclic\bin\ROOT.py", line 24, in <module>
import cppyy
File "C:\root\6.22.02vs19_aclic\bin\cppyy.py", line 61, in <module>
import libPyROOT as _backend
ImportError: DLL load failed: %1 is not a valid Win32 application.
>>>
that’s what I get in the terminal! Should I import some other modules?
Thank you for the help!
There is something that I am doing wrong with the evirnomental variables. If I call root from the terminal I get
C:\Users\Giammarco>root
'root' is not recognized as an internal or external command,
operable program or batch file.
But if I double click on the root.exe in each /bin folder of each version they run perfectly.
As a consequence python 32 bit (with an acrtive environment) throws the following:
(anaconda32) C:\Users\Giammarco>python
Python 3.8.3 (default, Jul 2 2020, 17:28:51) [MSC v.1916 32 bit (Intel)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ROOT'
>>>
My user environemental variables are
ROOTSYS = C:\root\6.22.02vs19_aclic;C:\root\5.34.36vs13_aclic;C:\root\5.34.38vs13_aclic;
PATH = %ROOTSYS%\bin
This cannot work. Either you change %ROOTSYS% to point to the only one version of ROOT you want to use, or you don’t set those variables at all and you call C:\root\6.22.02vs19_aclic\bin\thisroot.bat, orC:\root\5.34.36vs13_aclic\bin\thisroot.bat, orC:\root\5.34.38vs13_aclic\bin\thisroot.bat in a command prompt to properly set-up the environment variables before starting python
Python 3.8.3 (default, Jul 2 2020, 17:28:51) [MSC v.1916 32 bit (Intel)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Warning in <TClassTable::Add>: class ROOT::Detail::TTypedIter<class TEnumConstant> already in TClassTable
>>>
Nevertheless it is not a sustainable solution because I will use the v6.22 for python and the other 5.34.x for my current analysis! What’s your way of hopping among multiple versions of root on the same machine?
As I said, I use the thisroot.bat file to use different versions at the same time (you can have as many different versions running in their own command prompt session). And I know many people doing the same on different platforms