# Trouble with pyRoot

**URL:** <https://root-forum.cern.ch/t/trouble-with-pyroot/41995>\
**Category:** Newbie\
**Created:** [October 25, 2020, 4:46pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995 "2020-10-25T16:46:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![krausejm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/krausejm/32/23793_2.png) [@krausejm](https://root-forum.cern.ch/u/krausejm)\
**Post date:** [October 25, 2020, 4:46pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/1 "2020-10-25T16:46:17Z")

</div>

* * *

_ROOT Version:_ 6.22  
_Platform:_ Linux

greetings. i want to use root within python and followed the instructions here [https://root.cern/manual/python/](https://root.cern/manual/python/) which do not seem that complicated since root is already installed on my system. i can import root without problems in my python(scripts) BUT when i want to draw a canvas i get the standard notification

`Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1`

and the canvas is not drawn anywhere. i have the same problem on MacOS and im kind of stunned becaus i dont think its very complicated to use since i did some googlin around and everywhere it seems quite out of the box working. is there anything crucial i am missing? thanks in advance.

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 25, 2020, 4:52pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/2 "2020-10-25T16:52:38Z")

</div>

Welcome to the forum! Maybe our PyROOT expert @etejedor can help you

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [December 8, 2020, 11:13am UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/3 "2020-12-08T11:13:12Z")

</div>

Hello,

How did you run your Python code? In the Python prompt or via a script with `python script_name.py`?

If you don’t see the canvas, it’s probably because the Python process died. If you run your code from the Python prompt, you should see the canvas. If you run it as a script, you need to include the `-i` flag so the Python process is kept alive: `python -i script_name.py`.

---

<div class="post-metadata">

**Author:** ![krausejm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/krausejm/32/23793_2.png) [@krausejm](https://root-forum.cern.ch/u/krausejm)\
**Post date:** [December 9, 2020, 1:54pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/4 "2020-12-09T13:54:54Z")

</div>

hi,  
thanks for your answer. I already was working in a python prompt, i also tried jupyter notebooks (python) and use pyROOT there but that was not helping either. I also found the “solution” you mentioned running scripts with `python -i *.py` while googling this but without success. does it matter which python version im running? On both devices i installed ROOT before trying to use pyROOT is that maybe affecting this problem? needless to say i gave up using pyROOT since it does not work, which is not bad per se since i can use root without problem but it would be a nice feature.

cheers

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [December 9, 2020, 2:51pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/5 "2020-12-09T14:51:40Z")

</div>

Hi,

Ok, let’s try to diagnose the problem. First I would like to know whether the graphics work from the ROOT prompt but not from the Python prompt.

For that purpose, please run from the Python prompt:

```python
$ python
>>> import ROOT
>>> c = ROOT.TCanvas()

```

and now, from the ROOT prompt:

```auto
$ root
root [0] TCanvas c;

```

Could you confirm that you don’t see any canvas if you run it from the Python prompt in Python but you do see a canvas if you run it from the ROOT prompt in C++?

---

<div class="post-metadata">

**Author:** ![krausejm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/krausejm/32/23793_2.png) [@krausejm](https://root-forum.cern.ch/u/krausejm)\
**Post date:** [December 9, 2020, 3:56pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/6 "2020-12-09T15:56:52Z")

</div>

yes indeed, exactly this is the case.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [December 9, 2020, 4:19pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/7 "2020-12-09T16:19:08Z")

</div>

Ok, now let’s discard PyROOT is (for some reason) running in batch mode.

Can you run:

```auto
>>> import ROOT
>>> ROOT.gROOT.IsBatch()

```

Does it say true or false?

---

<div class="post-metadata">

**Author:** ![krausejm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/krausejm/32/23793_2.png) [@krausejm](https://root-forum.cern.ch/u/krausejm)\
**Post date:** [December 9, 2020, 7:30pm UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/8 "2020-12-09T19:30:04Z")

</div>

this returns True, i set it to False and now its working. thanks for the hint! but why does it start in batch mode in default?

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [December 10, 2020, 8:32am UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/9 "2020-12-10T08:32:59Z")

</div>

Hi,

Can you check if the variable `ROOTSYS` is defined in the environment where you run the Python prompt? If it is not defined, then you are missing this fix:

> <https://github.com/root-project/root/commit/23fbba2f126d0c33bc059384f279a6f954d182a5#diff-99c1321adf45e1356a5dccb621001c5baf3a1f69f71ed4ba1f3ad60c1f79c23f>

which is present from 6.22/06.

If that’s the case, you can either continue with an older 6.22 and explicitly disable the batch mode, or move to this newer version.

---

<div class="post-metadata">

**Author:** ![krausejm](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/krausejm/32/23793_2.png) [@krausejm](https://root-forum.cern.ch/u/krausejm)\
**Post date:** [December 10, 2020, 10:15am UTC](https://root-forum.cern.ch/t/trouble-with-pyroot/41995/10 "2020-12-10T10:15:24Z")

</div>

it was not defined. Thanks for your help, have a good one!
