greetings. i want to use root within python and followed the instructions here 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.
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.
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.
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
>>> import ROOT
>>> c = ROOT.TCanvas()
and now, from the ROOT prompt:
$ 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++?
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:
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.