# PyMVA with ROOT 6.06.04 does not compile with Python 3.6.5

**URL:** <https://root-forum.cern.ch/t/pymva-with-root-6-06-04-does-not-compile-with-python-3-6-5/28897>\
**Category:** TMVA\
**Tags:** python\
**Created:** [May 3, 2018, 11:03am UTC](https://root-forum.cern.ch/t/pymva-with-root-6-06-04-does-not-compile-with-python-3-6-5/28897 "2018-05-03T11:03:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgadrat](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sgadrat](https://root-forum.cern.ch/u/sgadrat)\
**Post date:** [May 3, 2018, 11:03am UTC](https://root-forum.cern.ch/t/pymva-with-root-6-06-04-does-not-compile-with-python-3-6-5/28897/1 "2018-05-03T11:03:03Z")

</div>

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](https://sft.its.cern.ch/jira/browse/ROOT-8177)

Any idea how to fix it?

Thanks, cheers,

Sébastien

[\*] Error found:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![sgadrat](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sgadrat](https://root-forum.cern.ch/u/sgadrat)\
**Post date:** [May 3, 2018, 12:49pm UTC](https://root-forum.cern.ch/t/pymva-with-root-6-06-04-does-not-compile-with-python-3-6-5/28897/2 "2018-05-03T12:49:52Z")

</div>

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](mailto:sebastien.gadrat@cc.in2p3.fr); roottalk (Mailing list for ROOT users.) [roottalk@cern.ch](mailto: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:

> <https://stackoverflow.com/questions/48849047/replacing-pystring-fromstring-method-in-python-3>

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

---

<div class="post-metadata">

**Author:** ![sgadrat](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sgadrat](https://root-forum.cern.ch/u/sgadrat)\
**Post date:** [May 15, 2018, 9:06pm UTC](https://root-forum.cern.ch/t/pymva-with-root-6-06-04-does-not-compile-with-python-3-6-5/28897/3 "2018-05-15T21:06:07Z")

</div>

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
