ImportError: No module named libPyROOT, After install Anaconda

Hi,

ROOT 6.13/03 Built for linuxx8664gcc From heads/master@v6-13-02-720-g49a64e5

How did I install root?

$ sudo mkdir /opt/root6
$ sudo chown andre /opt/root6
$ cd /opt/root6
$ git clone http://root.cern.ch/git/root.git root6_src
$ cmake -DPYTHIA8_DIR=/home/andre/pythia8226 -Dpythia8=ON -Dpython=ON -Droofit=ON -Dhttp=ON -Dccache=ON -Dcling=ON /opt/root6/root6_src/
$ sudo make -j4 && sudo make install
# This work very well!

And I get the following problem using the
command line: rootls -t file.root

Traceback (most recent call last):
  File "/opt/root6/bin/rootls", line 10, in <module>
    import cmdLineUtils
  File "/opt/root6/lib/cmdLineUtils.py", line 82, in <module>
    import ROOT
  File "/opt/root6/lib/ROOT.py", line 24, in <module>
    import cppyy
  File "/opt/root6/lib/cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: No module named libPyROOT

This error begin after install jupyter-notebook(root-notebook) with Anaconda:

$ python --version
Python 3.6.3 :: Anaconda, Inc.

Installed in the system: python2 and python3:

Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2

Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49) 
[GCC 7.2.0] on linux

to fix the problem I try using some tips in this post how-to-properly-install-pyroot-for-python

I try rebuild the root:

Add in the cmake config:

cmake  -DPYTHON_EXECUTABLE=/usr/bin/python -Dpython=ON /opt/root6/root6_src/
-- ROOT default compression algorithm is lz4
...
-- Found PythonInterp: /home/andre/anaconda3/bin/python (found version "3.6.3") 
-- Found NUMPY: /home/andre/anaconda3/lib/python3.6/site-packages/numpy/core/include (found version "1.13.3") 
...
-- Configuring done
CMake Warning at cmake/modules/RootNewMacros.cmake:629 (add_library):
  Cannot generate a safe runtime search path for target PyROOT because there
  is a cycle in the constraint graph:

    dir 0 is [/usr/local/lib]
      dir 1 must precede it due to runtime library [libTreePlayer.so]
    dir 1 is [/opt/root6/lib]
      dir 0 must precede it due to runtime library [libPyROOT.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootNewMacros.cmake:957 (ROOT_LINKER_LIBRARY)
  bindings/pyroot/CMakeLists.txt:16 (ROOT_STANDARD_LIBRARY_PACKAGE)


CMake Warning at cmake/modules/RootNewMacros.cmake:629 (add_library):
  Cannot generate a safe runtime search path for target PyMVA because there
  is a cycle in the constraint graph:

    dir 0 is [/usr/local/lib]
      dir 1 must precede it due to runtime library [libTMVA.so]
    dir 1 is [/opt/root6/lib]
      dir 0 must precede it due to runtime library [libPyROOT.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootNewMacros.cmake:957 (ROOT_LINKER_LIBRARY)
  tmva/pymva/CMakeLists.txt:20 (ROOT_STANDARD_LIBRARY_PACKAGE)


-- Generating done
-- Build files have been written to: /opt/root6

$ sudo make -j4 && sudo make install

[ 97%] Built target G__TMVAGui
[ 97%] Built target G__Genetic
[ 97%] Built target G__PyMVA
[ 97%] Built target G__Gviz3d
[ 97%] Built target G__Eve
[ 97%] Built target Genetic
Scanning dependencies of target HistFactory
[ 97%] Built target Gviz3d
Scanning dependencies of target TMVAGui
Scanning dependencies of target PyMVA
CMakeFiles/PyROOT.dir/src/Converters.cxx.o: In function `PyROOT::TConverter::FromMemory(void*)':
/opt/root6/root6_src/bindings/pyroot/src/Converters.cxx:138: undefined reference to `PyExc_TypeError'
/opt/root6/root6_src/bindings/pyroot/src/Converters.cxx:138: undefined reference to `PyErr_SetString'
CMakeFiles/PyROOT.dir/src/Converters.cxx.o: In function `PyROOT::TConverter::ToMemory(_object*, void*)':
/opt/root6/root6_src/bindings/pyroot/src/Converters.cxx:147: undefined reference to `PyExc_TypeError'
/opt/root6/root6_src/bindings/pyroot/src/Converters.cxx:147: undefined reference to `PyErr_SetString'
CMakeFiles/PyROOT.dir/src/Converters.cxx.o: In function `PyROOT::TVoidConverter::SetArg(_object*, PyROOT::TParameter&, PyROOT::TCallContext*)':
/opt/root6/root6_src/bindings/pyroot/src/Converters.cxx:479: undefined reference to `PyExc_SystemError'
/opt/root6/root6_src/bindings/pyroot/src/Converters.cxx:479: undefined reference to `PyErr_SetString'
...

CMakeFiles/PyROOT.dir/src/Utility.cxx.o: In function `PyROOT::Utility::ErrMsgHandler(int, bool, char const*, char const*)':
/opt/root6/root6_src/bindings/pyroot/src/Utility.cxx:831: undefined reference to `PyErr_WarnExplicit'
collect2: error: ld returned 1 exit status
bindings/pyroot/CMakeFiles/PyROOT.dir/build.make:979: recipe for target 'lib/libPyROOT.so' failed
make[2]: *** [lib/libPyROOT.so] Error 1
CMakeFiles/Makefile2:29013: recipe for target 'bindings/pyroot/CMakeFiles/PyROOT.dir/all' failed
make[1]: *** [bindings/pyroot/CMakeFiles/PyROOT.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 97%] Building CXX object tmva/pymva/CMakeFiles/PyMVA.dir/src/MethodPyAdaBoost.cxx.o
/opt/root6/root6_src/tmva/pymva/src/MethodPyAdaBoost.cxx:20:91: fatal error: Python.h: No such file or directory
compilation terminated.
tmva/pymva/CMakeFiles/PyMVA.dir/build.make:113: recipe for target 'tmva/pymva/CMakeFiles/PyMVA.dir/src/MethodPyAdaBoost.cxx.o' failed
make[2]: *** [tmva/pymva/CMakeFiles/PyMVA.dir/src/MethodPyAdaBoost.cxx.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:29675: recipe for target 'tmva/pymva/CMakeFiles/PyMVA.dir/all' failed
make[1]: *** [tmva/pymva/CMakeFiles/PyMVA.dir/all] Error 2
[ 97%] Built target TMVAGui
[ 98%] Built target HistFactory
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

Someone can help me? sorry by the long question

Cheers, Andre.

I had a progress on this issue…

cmake -DPYTHIA8_DIR=~/pythia8226 -DPYTHON3_EXECUTABLE=~/anaconda3/envs/my_env/lib/python3.6 -DPYTHON3_PACKAGES_PATH=~/anaconda3/envs/my_env35/lib/python3.6/site-packages/ -DPYTHON3_LIBRARY=~/anaconda3/envs/my_env/lib/libpython3.6m.so -DPYTHON_INCLUDE_DIR=~/anaconda3/envs/opencv3/include/python3.6m -Dpythia8=ON -Dpython=ON -Droofit=ON -Dhttp=ON -Dccache=ON -Dcling=ON /opt/root6/root6_src/
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TPyDispatcher.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TPyException.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TPyFitFunction.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TPyROOTApplication.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TPyReturn.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TPySelector.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TPython.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TSetItemHolder.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TTupleOfInstances.cxx.o
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/TemplateProxy.cxx.o
[ 94%] Built target G__RGL
make[2]: *** No rule to make target '/home/andre/anaconda3/envs/my_env/lib/libpython3.6.so', needed by 'lib/libPyROOT.so'.  Stop.
make[2]: *** Waiting for unfinished jobs....
[ 94%] Building CXX object bindings/pyroot/CMakeFiles/PyROOT.dir/src/Utility.cxx.o
Scanning dependencies of target TreeViewer
CMakeFiles/Makefile2:29013: recipe for target 'bindings/pyroot/CMakeFiles/PyROOT.dir/all' failed
make[1]: *** [bindings/pyroot/CMakeFiles/PyROOT.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 94%] Building CXX object tree/treeviewer/CMakeFiles/TreeViewer.dir/G__TreeViewer.cxx.o
[ 94%] Linking CXX shared library ../../lib/libTreeViewer.so
[ 94%] Built target TreeViewer
[ 94%] Built target G__TMVA
[ 94%] Built target G__RooStats
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

Cheers, Andre

Dear Andre, if you want to compile ROOT against anaconda’s Python, you must use GCC from anaconda instead of the system GCC. Please see https://sft.its.cern.ch/jira/browse/ROOT-9145 for more information.

Hi, Guilherme

Thanks for the reply. This is the answer, Now, I understand the problem. Just for the record, Let me explain:

python2 and python3 has differents GCC:

$ python2
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
>>> 
$ python3
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) 
[GCC 7.2.0] on linux

What I did, rebuild ROOT pointing to python2:

$ cmake -DPYTHIA8_DIR=/home/andre/pythia8226 -Dpythia8=ON -Dpython=ON -Dall=On -DPYTHON_EXECUTABLE=/usr/bin/python2 -Droofit=ON -Dhttp=ON -Dccache=ON -Dcling=ON /opt/root6/root6_src/

-- ROOT default compression algorithm is lz4
-- Found GCC. Major version 5, minor version 5
-- Found a 64bit system
-- Found GNU compiler collection
-- ROOT Platform: linux
-- ROOT Architecture: linuxx8664gcc

-- Found PythonInterp: /usr/bin/python2 (found version "2.7.12") 

The jupyter notebook working with the pyhton3.6 (from anaconda):

$ jupyter notebook
[I 10:03:27.813 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
[I 10:03:36.761 NotebookApp] JupyterLab beta preview extension loaded from /home/andre/anaconda3/lib/python3.6/site-packages/jupyterlab

As was say in the ROOT-9145:
“ROOT does not support integration between pyROOT and anaconda.”

ROOT don’t working with python3 in the moment.

Cheers, Andre

ROOT works with Python 3, but you have to use a compatible compiler (i.e. the same that was used to build Python itself), otherwise ROOT’s libraries will be ABI incompatible with the Python libraries, so they cannot be linked together. So, in your case, if you install GCC 7.2 from anaconda, and use that to compile ROOT, it should work with anaconda’s Python. Just make sure you don’t mix libraries from your system and from anaconda, because they are not guaranteed to be compatible.

Thank you for the explanation! it worked!

Cheers, Andre

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