Import ROOT, Error: Failed to import libcppyy3_7. Please check that ROOT has been built for Python 3.7

Dear experts,

I download a pre-compiled binary distribution ROOT6.28.04 and install it in Ubuntu 18.04.

Then I write the configuration file as follows:

# root6
  export ROOTSYS="/mnt/work/soft/root6.28.04/"
  export PATH="$PATH:$ROOTSYS/bin"
  export PYTHONDIR=$ROOTSYS
  export LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$ROOTSYS/bindings/pyroot:$LD_LIBRARY_PATH
  export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH:$ROOTSYS/bindings/pyroot
 
 alias root="source /mnt/work/soft/root6.28.04/bin/thisroot.sh && root"

 20 # >>> conda initialize >>>
  __conda_setup="$('/mnt/public/shuangli/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
 if [ $? -eq 0 ]; then
 eval "$__conda_setup"
 else
 if [ -f "/mnt/public/shuangli/anaconda3/etc/profile.d/conda.sh" ]; then
 .  "/mnt/public/shuangli/anaconda3/etc/profile.d/conda.sh"
 else
 export PATH="/mnt/public/shuangli/anaconda3/bin:$PATH"
   fi
 fi
 unset __conda_setup
 # <<< conda initialize <<<
 
 conda deactivate
 conda activate my_env

When I import the ROOT, an error is given:

  import ROOT
  File "/mnt/work/soft/root6.28.04/lib/ROOT/__init__.py", line 25, in <module>
    import cppyy
  File "/mnt/work/soft/root6.28.04/lib/cppyy/__init__.py", line 64, in <module>
    libcppyy_mod_name, major, minor))
ImportError: Failed to import libcppyy3_7. Please check that ROOT has been built for Python 3.7

After checking, namely root-config --python-version, the python version is 3.6.9, which is different from my python 3.7.16.

My question is why is the version of python inconsistent when I do this?

With best respect,
Boan

By the way, installing ROOT via conda is an alternative way, but the time is too long.

Hi,
The problem is the incompatibility of the Python versions. Try building ROOT from source or install it via Conda

Lorenzo

Thank you, Lorenzo!

The situation is exactly as you mentioned.

In order to clarify for others how the problem can be solved, I’ll explain my specific situation here.

I use someone else’s miniconda, and the python in the base environment is 3.6.9. Therefore, even though I have install python 3.7.16 in my new environment, importing pre-compiled ROOT applies the older python version.

According to this, my solution is formulated as follows:

1: Use my own miniconda.
2: Install ROOT via conda. Following the tutorial, use conda config --set channel_priority strict to dramatically accelerate the entire installation process.
3: Check the environment and the version of python. It must be the same, otherwise it will give you an error like mine.

The above is the experience of a python beginner.

Boan

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