# "import ROOT" is not working in root 6.26

**URL:** <https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803>\
**Category:** ROOT\
**Created:** [February 27, 2023, 5:39pm UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803 "2023-02-27T17:39:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajit](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ajit/32/21373_2.png) [@ajit](https://root-forum.cern.ch/u/ajit)\
**Post date:** [February 27, 2023, 5:39pm UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803/1 "2023-02-27T17:39:06Z")

</div>

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  
\_Compiler:c++11

* * *

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [February 27, 2023, 7:20pm UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803/2 "2023-02-27T19:20:16Z")

</div>

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](https://root.cern/install) ?

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.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![ajit](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ajit/32/21373_2.png) [@ajit](https://root-forum.cern.ch/u/ajit)\
**Post date:** [February 27, 2023, 9:53pm UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803/3 "2023-02-27T21:53:16Z")

</div>

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?

Thanks  
Ajit

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [February 28, 2023, 7:19am UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803/4 "2023-02-28T07:19:32Z")

</div>

Dear @ajit ,

First of all, I would try to install ROOT via your system package manager or, failing that, via [conda](https://root.cern/install/#conda) (you could even use mamba for faster installation, as I suggested in [other posts](https://root-forum.cern.ch/t/root-build-with-python-3-7-in-centos7/53162/8)).

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.

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![ajit](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ajit/32/21373_2.png) [@ajit](https://root-forum.cern.ch/u/ajit)\
**Post date:** [February 28, 2023, 10:34am UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803/5 "2023-02-28T10:34:29Z")

</div>

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.

Thanks  
Ajit

---

<div class="post-metadata">

**Author:** ![ajit](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ajit/32/21373_2.png) [@ajit](https://root-forum.cern.ch/u/ajit)\
**Post date:** [February 28, 2023, 12:06pm UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803/6 "2023-02-28T12:06:27Z")

</div>

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  
Ajit

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 14, 2023, 12:06pm UTC](https://root-forum.cern.ch/t/import-root-is-not-working-in-root-6-26/53803/7 "2023-03-14T12:06:59Z")

</div>

Closed on March 14, 2023, 12:06pm UTC

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