Python 2.7 forced by LLVM?


_ROOT Version: v6.18/00
_Platform: Linux/Fedora30 x86_64
_Compiler: g++ (GCC) 8.3.0 (downgraded)


It’s high time and I’m trying to convert from python2 to py3…

On Fedora, py2 and py3 still coexist. (I’m willing to remove py2 if possible)

After building root w/ (python-related options only)

python    OFF
python3    ON
PYTHON_EXECUTABLE       /usr/bin/python3
PYTHON_INCLUDE_DIR      /usr/include/python3.7m
PYTHON_LIBRARY          /usr/lib64/libpython3.so

libPyROOT.so still uses libpython2.7.so.1.0.

[furutaka@Furutaka-3 lib]$ ldd libPyROOT.so|grep python
	libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0 (0x000014b67304b000)

It seems to me that this cause the following error:

[furutaka@Furutaka-3 ~]$ python3
Python 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/root/lib/ROOT.py", line 24, in <module>
    import cppyy
  File "/usr/local/root/lib/cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: dynamic module does not define module export function (PyInit_libPyROOT)
>>>

Renaming the py2.7 lib and cmake’ing from scratch yields the following error:

CMake Error at interpreter/llvm/src/CMakeLists.txt:613 (if):
  if given arguments:

    "VERSION_LESS" "2.7"

  Unknown arguments specified


-- Configuring incomplete, errors occurred!

The corresponding part of the interpreter/llvm/src/CMakeLists.txt reads:

    601 # Verify that we can find a Python 2 interpreter.  Python 3 is unsupported.
    602 # FIXME: We should support systems with only Python 3, but that requires work
    603 # on LLDB.
    604 set(Python_ADDITIONAL_VERSIONS 2.7)
    605 include(FindPythonInterp)
    606 if( NOT PYTHONINTERP_FOUND )
    607   message(FATAL_ERROR
    608 "Unable to find Python interpreter, required for builds and testing.
    609 
    610 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
    611 endif()
    612 
    613 if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
    614   message(FATAL_ERROR "Python 2.7 or newer is required")
    615 endif()

This way, it seems LLVM is forcing the use of py2.

What is the correct/proper way to build root with python3?

Thanks…
Kazuyoshi

Well… The libPyROOT.so file seems to be a remnant of an old build and with the following python-related options the file was NOT CREATED!!!

[furutaka@Furutaka-3 tmp]$ awk 'tolower($0)~/python/{print}' ../RootBuildOptions.cmake
# move to python3
set(python    OFF CACHE BOOL "")
set(python3    ON CACHE BOOL "")
set(PYTHON_EXECUTABLE       /usr/bin/python3 CACHE FILEPATH "")
set(PYTHON_INCLUDE_DIR      /usr/include/python3.7m CACHE PATH "")
set(PYTHON_LIBRARY          /usr/lib64/libpython3.so CACHE FILEPATH "")
#set(CPACK_PACKAGE_EXECUTABLES "root-py3" "ROOT (Python 3)")

The cmake run shows (again only python-related lines were excerpted)

 [furutaka@Furutaka-3 tmp]$ awk 'tolower($0)~/python/{print}' cmake___.log 
-- Looking for python
-- Found PythonInterp: /usr/bin/python (found version "2.7.16") 
-- Found PythonLibs: /usr/lib64/libpython2.7.so (found version "2.7.16") 
-- Found NUMPY: /usr/lib64/python2.7/site-packages/numpy/core/include (found version "1.16.3") 
-- Enabled support for:  asimage astiff builtin_afterimage builtin_clang builtin_davix builtin_ftgl builtin_glew builtin_llvm builtin_tbb builtin_vdt builtin_xxhash clad cling davix exceptions explicitlink fftw3 fitsio gdml http imt mathmore mysql opengl pch pgsql python roofit shared sqlite ssl thread tmva tmva-cpu tmva-pymva vdt x11 xml

Kazuyoshi

With -Dpython=OFF you effectively disabled Python support from ROOT. You need -Dpython=ON -DPYTHON_EXECUTABLE=$(which python3) to configure with Python 3.x. The -Dpython3=ON option has been removed since a while, since it didn’t work properly.

2 Likes

Thanks, amadio!

By building with the following setting, I finally get root-6.18/00 running w/ Python3/PyROOT!

 $ cmake -Dcxx14=ON -Dgdml=ON -Dminuit2=ON -Dpython=ON -Droofit=ON -Dgsl_shared=ON -DLLVM_ENABLE_DOXYGEN=ON -DLLVM_ENABLE_SPHINX=ON -DCMAKE_INSTALL_PREFIX=/usr/local/root -DPYTHON_EXECUTABLE=$(which python3) -DTHREADS_PREFER_PTHREAD_FLAG=TRUE -DCMAKE_THREAD_PREF${CMAKE_CXX_FL -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -pthread"
[furutaka@Furutaka-3 root-build-v6-18-00]$ cd
[furutaka@Furutaka-3 ~]$ python3
Python 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> 

Kazuyoshi

3 Likes

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