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
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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?
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.