"import ROOT" is not working in root 6.26

I have installed root but “import ROOT” is not working.
I then recompiled root with the following command…
$cmake -Dpyroot=ON -Dpyroot_legacy=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_INSTALL_PREFIX=root_install root_src
$cmake --build . --target install

but it gives me following error…
/home/akumar/root/root_src/bindings/pyroot_legacy/src/PyROOT.h:110:45: error: ‘_PyUnicode_AsStringAndSize’ was not declared in this scope; did you mean ‘PyUnicode_FromStringAndSize’?
110 | #define PyROOT_PyUnicode_AsStringAndSize _PyUnicode_AsStringAndSize
| ^~~~~~~~~~~~~~~~~~~~~~~~~~


Could you please help me in this regards.

_ROOT Version:6.26
_Platform:ubuntu 22.04

Hi @ajit ,

Thanks for reaching out. Is there a reason why you need to compile ROOT yourself? Can’t you use one of the available installation options at Installing ROOT - ROOT ?

If you truly need to compile ROOT yourself, I don’t think there’s any reason why you should ask for -Dpyroot_legacy=ON, we have had the new PyROOT since a while now.


hi @vpadulan ,

Thanks for your reply. I don’t know if I can use the pre-compiled for my purpose. I will check if works.

For the time being I am compiling ROOT by myslef.
I am doing “-Dpyroot_legacy=ON” because my “import ROOT” was not working. I was looking for solution on web and somewhere it was suggested to use the above (-Dpyroot_legacy=ON) option. That is why I used.

After compiling ROOT by myslef I checked “root-config --has-pyroot”. The output of this was “No”. I don’t know why.

Could you please suggest where I am doing mistake?


Dear @ajit ,

First of all, I would try to install ROOT via your system package manager or, failing that, via conda (you could even use mamba for faster installation, as I suggested in other posts).

If you are still sure you want to compile ROOT yourself afterwards, just build without -Dpyroot_legacy=ON and see if that is enough. Remember that you still need to source thisroot.sh after compilation if you want to import ROOT in your python scripts. And remember that it must be the same Python executable that you used to build ROOT with.


Dear @vpadulan ,
I tried building ROOT without -Dpyroot_legacy=ON, but I am getting still the same error (home/akumar/root/root_src/bindings/pyroot_legacy/src/PyROOT.h:109:45: error: ‘_PyUnicode_AsStringAndSize’ was not declared in this scope; did you mean ‘PyUnicode_FromStringAndSize’?
109 | #define PyROOT_PyUnicode_AsStringAndSize _PyUnicode_AsStringAndSize

If I am compiling with python2 then it is not showing any error, but I want to compile with python3.


Dear @vpadulan ,

It works now.
I removed my build directory and recompiled from scratch without -Dpyroot_legacy=ON. Now it is working fine.

Thanks for the help.

Best Regards

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