RootPy installation - ROOT cannot be imported?

Thanks, I will read up on environment modules and try to implement this. Could you please point out the wrong/redundant entries? I’m not sure which one’s which, except that /bin contains binaries and /lib contains libraries :sweat_smile:

Of course you could simply source thisroot.sh, but if you want to add them manually here is a set of environment variable that may be set. You may not need them all (JUPYTER_PATH, …), and there may be other you want to set as well (LD_LIBRARY_PATH, …), and others that shouldn’t need to be set, but may need to be set based on your configuration (MAN_PATH, …).

export ROOTSYS=/path/to/root
export LIBRARY_PATH=${LIBRARY_PATH}:${ROOTSYS}/lib
export PYTHONPATH=${PYTHONPATH}:${ROOTSYS}/lib
export CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}:${ROOTSYS}
export JUPYTER_PATH=${JUPYTER_PATH}:${ROOTSYS}/etc/notebook
export PATH=${PATH}:${ROOTSYS}/bin

Hi @hkl

-Dpython_executable=/usr/local/bin/python3.7m/

is not a path to a binary, it is a path to a directory. See my example:

PYTHON_EXECUTABLE:FILEPATH=/cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517python3/x86_64-centos7-gcc7-opt/bin/python

You need to specify there the full path to your python binary (perhaps /usr/local/bin/python3.7 ? )

Try to run which python3 to check where it is.

Thanks, I will add this (and source thisroot.sh)! Should I keep any of those:

PATH=$PATH:/localscratch/user/root_6.14.04/bindings/pyroot/
PYTHONPATH=$PYTHONPATH:/localscratch/user/root_6.14.04/bindings/pyroot/

Don’t do both. If you are happy with sourcing thisroot.sh, just do that and leave the environment variables alone.

Ok. If I would like to use ROOT in Jupyter, should I just source thisroot.sh and only add export JUPYTER_PATH=${JUPYTER_PATH}:/path-to-root/etc/notebook/?

It appears that JUPYTER_PATH is already set in thisroot.sh:

@ksmith: Thanks for this bit!

I’ve rebuilt ROOT using

sudo cmake -Dall=ON -Dpython3=ON -Dpython_executable=/usr/bin/python3.5m/ -Dpython_library=/usr/lib/python3.5/ -Dpython_include_dir=/usr/include/python3.5m/ /localscratch//root-6.14.04/
sudo cmake --build .

Once again, import ROOT works only in Python 2.7.13, even though I set -Dpython3=ON. In Python 3.5.3 I get:

>>> import ROOT
Traceback (most recent call last):
File “”, line 1, in
File “/localscratch//root_6.14.04/lib/ROOT.py”, line 24, in
import cppyy
File “/localscratch//root_6.14.04/lib/cppyy.py”, line 61, in
import libPyROOT as _backend
ImportError: dynamic module does not define module export function (PyInit_libPyROOT)

Also, for some reason, source thisroot.sh throws errors (bash: cd: too many arguments, bash: sed: No such file or directory, bash: grep: command not found) and I have to reboot in order for this to execute.

@etejedor: Doing which python3.5 gives /usr/bin/python3.5… Could it be that ROOT requires the use of exactly /python3 (instead of /python3.5, /python3.5m or /python3.7)? And maybe the trailing backslashes are causing trouble (files getting interpreted as folders)…

I’m rebuilding (again :sweat_smile:) using:

sudo cmake -Dall=ON -Dpython3=ON -Dpython_executable=/usr/bin/python3.5 -Dpython_library=/usr/lib/python3.5 -Dpython_include_dir=/usr/include/python3.5 /localscratch//root-6.14.04/

/edit: Okay, same result! import ROOT works in Python 2, but not Python 3. Not sure what I’m missing here… CMakeCache.txt did not contain any such long entries for either of the three options. For PYTHON_LIBRARY, do I need to explicitly point to a .SO-file?

Hi @hkl

Can you paste here what your CMakeCache.txt file contains for PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIR and PYTHON_LIBRARY?

Enric

Hi,

these are the lines in CMakeCache.txt:

PYTHON_EXECUTABLE:FILEPATH=/usr/bin/python
PYTHON_INCLUDE_DIR:PATH=/usr/include/python2.7
PYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython2.7.so

It seems CMake didn’t use the options given by

sudo cmake -Dall=ON -Dpython3=ON -Dpython_executable=/usr/bin/python3.5 -Dpython_library=/usr/lib/python3.5 -Dpython_include_dir=/usr/include/python3.5 /localscratch/user/root-6.14.04/

for which the terminal output says

-- Found PythonInterp: /usr/bin/python (found version "2.7.13")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found version "2.7.13")
-- Found NUMPY: /usr/local/lib/python2.7/dist-packages/numpy/core/include (found version "1.14.5")

It’s the caps, using upper-case commands sets the options right. After rebuild, import ROOT finally works in Python 3.5.3 and (as intended) does not in Python 2.7.13.

Unfortunately, both sudo pip install rootpy and sudo pip3 install rootpy still throw the error

ROOT cannot be imported. Is ROOT installed with PyROOT enabled?

Not sure whether this is relevant, but doing which python gives /usr/bin/python. The latter appears to be a link to /etc/alternatives/python, which again links to /usr/bin/python3.5m (the shared library). Everything good here, right?

As suggested here, I tried copying ROOT.py and libPyROOT.so into /usr/lib/, /usr/lib/python3.5, and /usr/lib/x86_64-linux-gnu, but this does not help either. Any ideas?

Hi @hkl

Since this is a rootpy issue, not ROOT, I am afraid I can’t be of much help. You were able to successfully import ROOT from the Python prompt, so I can’t really tell what rootpy is missing.

Enric

Okay, I will try uproot next as @sbinet suggested and leave this issue open. At the end, I want to work with data contained in ROOT files using Python (e.g. Jupyter).

Thanks a ton!

Hi @hkl

Please note you can also use PyROOT :slight_smile: without rootpy. We are here to assist you with any question you might have. What is exactly what you want to do?

Cheers,
Enric

Hi Enric,

I’d like to import the relevant data (histograms etc.) from ROOT files into Python for further analysis. The files were generated by the DAQ program (open-source, written in ROOT) for the CAEN A1702 board used to readout SiPMs.

Cheers,
HK

Then, yes, installing uproot would definitely be an interesting option (considering your troubles with recompiling ROOT on your machine, as indicated in the other thread.)

#> pip install uproot

And off you go.

Even installing Groot could be an option (a pure-Go package to read and write (some) ROOT objects)

$> go get go-hep.org/x/hep/groot/...

(You’ll need to install the Go toolchain: https://golang.org
Don’t worry, it’s a very simple procedure.)

hth.

1 Like

Hi @hkl

You can definitely do that with PyROOT only. See for instance this example of reading TTree branches from PyROOT:

How is your code in Python looking right now?

Enric

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.