PyMVA with ROOT 6.06.04 does not compile with Python 3.6.5

Hi all,

I am trying to compile ROOT v6.06.04, against python 3.6.5 and numpy
1.14.2. The compilation failed at almost the end with the following
error (see below [*]). I am using the native CentOS 7 compiler which is
4.8.5.

The problem seems to be related to numpy, however I could compile ROOT
v6.13.02 against the same python and numpy without any problem (with the
same compiler).

I googl-ed it, and find that bug report, which is still in open state:

https://sft.its.cern.ch/jira/browse/ROOT-8177

Any idea how to fix it?

Thanks, cheers,

SĂ©bastien

[*] Error found:

from
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/PyMethodBase.cxx:14:
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/PyMethodBase.cxx:
In static member function 'static void TMVA::PyMethodBase::PyInitialize()':
/pbs/software/centos-7-x86_64/python/3.6.5/lib/python3.6/site-packages/numpy/core/include/numpy/__multiarray_api.h:1542:35:
error: return-statement with a value, in function returning 'void'
[-fpermissive]
 #define NUMPY_IMPORT_ARRAY_RETVAL NULL
                                   ^
/pbs/software/centos-7-x86_64/python/3.6.5/lib/python3.6/site-packages/numpy/core/include/numpy/__multiarray_api.h:1547:151:
note: in expansion of macro 'NUMPY_IMPORT_ARRAY_RETVAL'
 #define import_array() {if (_import_array() < 0) {PyErr_Print();
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to
import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }
                                                                                                                                                      
^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/PyMethodBase.cxx:91:7:
note: in expansion of macro 'import_array'
       import_array();
       ^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/PyMethodBase.cxx:94:55:
error: 'PyString_FromString' was not declared in this scope
    PyObject *bName = PyString_FromString("__builtin__");
                                                       ^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/PyMethodBase.cxx:
In static member function 'static void
TMVA::PyMethodBase::PySetProgramName(TString)':
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/PyMethodBase.cxx:136:53:
error: cannot convert 'char*' to 'wchar_t*' for argument '1' to 'void
Py_SetProgramName(wchar_t*)'
    Py_SetProgramName(const_cast<char *>(name.Data()));
                                                     ^
gmake[2]: *** [tmva/pymva/CMakeFiles/PyMVA.dir/src/PyMethodBase.cxx.o]
Error 1
gmake[2]: *** Waiting for unfinished jobs....
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyGTB.cxx:
In member function 'virtual void TMVA::MethodPyGTB::Init()':
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyGTB.cxx:309:60:
error: 'PyString_FromString' was not declared in this scope
    PyObject *pName = PyString_FromString("sklearn.ensemble");
                                                            ^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyGTB.cxx:
In member function 'virtual void TMVA::MethodPyGTB::Train()':
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyGTB.cxx:423:42:
error: 'PyString_AsString' was not declared in this scope
    PyData << PyString_AsString(model_data);
                                          ^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyRandomForest.cxx:
In member function 'virtual void TMVA::MethodPyRandomForest::Init()':
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyRandomForest.cxx:282:60:
error: 'PyString_FromString' was not declared in this scope
    PyObject *pName = PyString_FromString("sklearn.ensemble");
                                                            ^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyRandomForest.cxx:
In member function 'virtual void TMVA::MethodPyRandomForest::Train()':
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyRandomForest.cxx:393:42:
error: 'PyString_AsString' was not declared in this scope
    PyData << PyString_AsString(model_data);
                                          ^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyAdaBoost.cxx:
In member function 'virtual void TMVA::MethodPyAdaBoost::Init()':
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyAdaBoost.cxx:178:60:
error: 'PyString_FromString' was not declared in this scope
    PyObject *pName = PyString_FromString("sklearn.ensemble");
                                                            ^
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyAdaBoost.cxx:
In member function 'virtual void TMVA::MethodPyAdaBoost::Train()':
/pbs/throng/ccin2p3/support/gadrat/root/root/tmva/pymva/src/MethodPyAdaBoost.cxx:264:42:
error: 'PyString_AsString' was not declared in this scope
    PyData << PyString_AsString(model_data);
                                          ^
gmake[2]: *** [tmva/pymva/CMakeFiles/PyMVA.dir/src/MethodPyGTB.cxx.o]
Error 1
gmake[2]: ***
[tmva/pymva/CMakeFiles/PyMVA.dir/src/MethodPyRandomForest.cxx.o] Error 1
gmake[2]: ***
[tmva/pymva/CMakeFiles/PyMVA.dir/src/MethodPyAdaBoost.cxx.o] Error 1
gmake[1]: *** [tmva/pymva/CMakeFiles/PyMVA.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
[ 95%] Built target Genetic
[ 95%] Linking CXX shared library ../../lib/libTMVAGui.so
[ 96%] Built target TMVAGui
[ 96%] Linking CXX shared library ../../lib/libEve.so
[100%] Built target Eve
gmake: *** [all] Error 2

Anwser received from the root-talk mailing list.

From: Enric Tejedor Saavedra
Sent: 03 May 2018 13:48
To: Sebastien Gadrat sebastien.gadrat@cc.in2p3.fr; roottalk (Mailing list for ROOT users.) roottalk@cern.ch
Subject: Re: PyVMA with ROOT 6.06.04 does not compile with Python 3.6.5

Hi SĂ©bastien,

This looks like a bug in TMVA in 6.06, where the PyString_FromString function was used in several places. This function is no longer present in Python>=3.5 and, instead, the PyUnicode_FromString function should be used, as pointed out here:

This bug has already been fixed, that’s why you do not see the same error in 6.13.

I will let Lorenzo further comment on it since he is responsible for the ticket you mentioned.

Cheers,

Enric

1 Like

Hi Enric,

Thanks for your answer!

Since this bug has been fixed in more recent ROOT versions, would it be possible to backport it to version 6.06.04 (if a patch exists)? I can apply it “manually” on my local ROOT installation if needed. Maybe I can just try a “query-replace” in TMVA?

Thanks, cheers,

SĂ©bastien