ModuleNotFoundError when using @ROOT.Numba : No module named 'numba'

Hi Root Expert,
I experienced a couple of import errors when running this simple code:

import ROOT
# To mark a Python callable to be used from C++, you have to use the decorator
# provided by PyROOT passing the C++ types of the input arguments and the return
# value.
@ROOT.Numba.Declare(['float', 'int'], 'float')
def pypow(x, y):
    return x**y
# The Python callable is now available from C++ in the Numba namespace.
# For example, we can use it from the interpreter.
ROOT.gInterpreter.ProcessLine('cout << "2^3 = " << Numba::pypow(2, 3) << endl;')
# Or we can use the callable as well within a RDataFrame workflow.
data = ROOT.RDataFrame(4).Define('x', '(float)rdfentry_')\
                         .Define('x_pow3', 'Numba::pypow(x, 3)')\
print('pypow({}, 3) = {}'.format(data['x'], data['x_pow3']))

when running with the default python 2.7.5, I got:

Traceback (most recent call last):
File “…/”, line 10, in
@ROOT.Numba.Declare([‘float’, ‘float’], ‘float’)
File “/usr/lib64/python2.7/site-packages/ROOT/”, line 316, in Numba
raise Exception(‘ROOT.Numba requires Python above version {}.{}.{}’.format(*_numba_pyversion))
Exception: ROOT.Numba requires Python above version 2.7.5

Then I switched to python3.6, and I got longer errors: raceback (most recent call last):

File “/usr/lib64/python3.6/site-packages/ROOT/”, line 28, in _NumbaDeclareDecorator
import numba as nb
File “/usr/lib64/python3.6/site-packages/ROOT/”, line 150, in _importhook
return _orig_ihook(name, *args, **kwds)
ModuleNotFoundError: No module named ‘numba’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “…/”, line 10, in
@ROOT.Numba.Declare([‘float’, ‘float’], ‘float’)
File “/usr/lib64/python3.6/site-packages/ROOT/”, line 30, in _NumbaDeclareDecorator
raise Exception(‘Failed to import numba’)
Exception: Failed to import numba

ROOT Version: 6.24/06
Platform: lxplus7
Compiler: Not Provided

Appreciate it if you could have a look and give me a hand!

Hi @zhiyuanlcern ,

welcome to the ROOT forum and sorry for the high latency.

The first error is because ROOT.Numba.Declare requires Python 3.
The second error (ModuleNotFoundError: No module named ‘numba’) is because the python3.6 installation you are using does not include numba (you can check with /usr/lib64/python3.6 -c 'import numba'.

On LXPLUS a recent LCG view works:

[eguiraud@lxplus767 ~]$ source /cvmfs/
[eguiraud@lxplus767 ~]$ python --version
Python 3.9.12
[eguiraud@lxplus767 ~]$ python -c 'import numba'
[eguiraud@lxplus767 ~]$ vim scratch/ # is your code above
[eguiraud@lxplus767 ~]$ python scratch/
2^3 = 8
pypow([0. 1. 2. 3.], 3) = [ 0.  1.  8. 27.]


Hi Enrico,
Thanks a lot, it works perfectly fine now!

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