Error in installing ROOT in conda environment for python 2.7: Failed to import libcppyy

ROOT Version: 6.22.0
Platform: Mac 11.4
Python2.7

Hello!

Sorry if I am not expressing myself in the correct jargon, but I am fairly new with these topics.

I have ROOT already running on my local machine, now I am working inside an Anaconda environment with Python 2.7. When setting up the environment I directly installed ROOT version 6.22 (compatible with Python 2.7) - it is also listed with
conda list root

However when wanting to import ROOT inside python, I am getting the following error message:

“Traceback (most recent call last):
File “”, line 1, in
File “/Users/FranzkeMM/root_v6.26.00/lib/ROOT/init.py”, line 22, in
import cppyy
File “/Users/FranzkeMM/root_v6.26.00/lib/cppyy/init.py”, line 64, in
libcppyy_mod_name, major, minor))
ImportError: Failed to import libcppyy2_7. Please check that ROOT has been built for Python 2.7”

so it seems, that python somehow looks for root on the version that is locally installed and not via Anaconda.

So my idea would have been to prevent this with sourcing like this:

source ~/opt/anaconda3/pkgs/root-binaries-6.22.0-py27hdf2d85e_2/bin/thisroot.sh

But the message is being returned:
" ERROR: thisroot.sh, thisroot.csh and thisroot.fish should never be used

Look at using “conda activate ENVIRONMENT_NAME”

Any ideas on what is happening? Thanks a lot in advance!

P.S. when sourcing to the thisroot.sh file of the locally installed root, it is working, but this is in general not what I want of course

Hi @mike_f ,
checking the obvious first, did you run conda activate yourenvironmentname before starting python? (EDIT: in a terminal where you did not source /Users/FranzkeMM/root_v6.26.00/bin/thisroot.sh first?)

If you have a source .../thisroot.sh line in your bashrc or .profile you should also remove it.

Cheers,
Enrico

Thanks eguiraud for the reply!

I was working inside the environment, but indeed I didn’t think about the bash_profile…

So thanks for pointing this out and sorry for bothering you with this

Cheers,
Michael