Error while using pyROOT " use of undeclared identifier 'TPython' "

Dear ROOT experts,
I’m trying to follow this post RDataFrame: Defining new column evaluated as a function of external values in Python to define an external value.
However when i try to run the code below:

import ROOT

x = 5
ROOT.gInterpreter.Declare("""
   const double x = double(TPython::Exec("x"));
""")

I get the following error:

input_line_37:2:28: error: use of undeclared identifier 'TPython'
   const double x = double(TPython::Exec("x"));

How can i solve this error?
I compiled root from source, and I am using python 3.11.


ROOT Version: 6.28/02
Platform: MacOS M1. Monterey 12.6.1


HI! Maybe @vpadulan has an idea about what’s going on here?

Hi @AntoninoFulci ,

I can’t reproduce your problem, I’m on Fedora with ROOT installed from anaconda in an environment with Python 3.11

Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> 
>>> x = 5
>>> ROOT.gInterpreter.Declare("""
...    const double x = double(TPython::Exec("x"));
... """)
True
>>> 
>>> 

Also same thing when executing the script, no error shown

$: python repro.py
$:

Small update:
I tried with different environments, one with ROOT 6.28 and one with ROOT 6.26, no error in either case.

I’m on MacOS (M1 chip) with a compiled version of root. This is not the first time I encounter this error, I also had this issue when using root 6.26.

However, I re-installed root using conda and now I don’t have this problem anymore.

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