I am working with PyROOT in my master thesis and I got some messy code to work with which is not formatted correctly according to pep8. I thought in the process of going through the code I could try to “correct” the code and format it properly.
The following is just a question of interest which I was not able to figure out.
While I have no problems with the command
There is a warning when I try for example
from ROOT import TTree
which is “no-name-in-module: no name ‘TTree’ in module ‘ROOT’”. The code compiles without a problem, I was just wondering how I can add the modules of ROOT to my PYTHONPATH variable so that they are seen. The variable is currently set to
but apparently the modules are not listed there for python, I guess. Is there a workaround to fix this “problem”?
Thanks in advance!
What version of ROOT are you using? How did you install ROOT?
TTree is provided out-of-the-box in PyROOT, so a failure in looking it up indicates there is some problem with the ROOT installation / the configuration of the environment.
I am using ROOT Version 6.22/02.
I first tried to build it, but this did not work out of the box for me, so I deleted the files and used the pre-compiled binary distribution for Ubuntu 20. I am using Ubuntu 20.04.1. I created a directory in my home directory .ROOT and unpacked the files to it. Afterwards I sourced thisroot.sh.
The python version I am using is 3.8.2.
What you are doing looks ok.
Can you try a few things?
- Does the ROOT prompt (C++) work? Can you use TTree from there?
- What happens if you execute:
does that give you the same lookup error as for TTree?
Just to clarify:
The code compiles also in PyROOT without a problem, so the modules are ready to use.
It is just a formal problem I was wondering about, since pylint does not find all modules of ROOT.
The only modules that are found by pylint are:
cppyy, sys, importlib, major, minor, librootpyz_mod_name, pyz, functools, pkgutil, pythonization, exclude, module_name, module, builtins, ip, JupyROOT, JsMVA, atexit, cleanup, environ, path, ROOTFacade, get_ipython
which I get from the pylint error message when I type
from ROOT import *
gives the same lookup error.
Ok, so you get that message from pylint, not from the Python interpreter when you try to run the code, right?
The thing with PyROOT is that everything is dynamic, there is no
TTree Python class that is created beforehand. What happens is that, by interrogating the ROOT C++ interpreter, PyROOT can learn about C++ entities (e.g. classes) at runtime and create Python proxies for them. That must be the reason why you get that message from pylint, since there is no TTree class in the PYTHONPATH, it’s created on the fly.