Problem with pyroot on macOS 10.15.6 and Python 2.7.16

Dear all,
I want to try pyroot on my computer. And if I run python2 and it works perfectly:

(base) [bogon@Cassandra:] ~/pyroot $ python2
WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Jun 5 2020, 22:59:21) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from ROOT import TGraph
>>> gr = TGraph('data.txt')
>>> gr.Draw()
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
>>> exit()

But when I run python2 with .py document, the graph became no response. Sometimes it won’t even show the graph.

[bogon@Cassandra:] ~/pyroot $ python2 try.py 
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1

Is there any way to fix this ?

Thanks!


ROOT Version: ROOT 6.22/02
Platform: macOS 10.15.6

Welcome to the ROOT forum!

The problem is that the python process closes after execution before it has a chance to show the graph to you. In order to keep python open so that you can look at the graphics output, you can start python in interactive mode with python2 -i try.py.

Hello!
Thank you very much! That did solve my problem. But here is another one. My colleague solve this problem by adding input() at the end of his code. But when I do the same thing, the graph shows but has no response. I can’t do anything to the graph. Do you know how to fix it?

Can you attach your try.py script so that I can try to reproduce the issue?

from ROOT import TCanvas,TF1,TGraph
gr = TGraph('data.txt')
gr.Draw()
input()

While the data.txt contains:

 1    1
 2    2
 3    3

Hm, your script actually does work for me, e.g. on lxplus. Still, you could try the following extension to the script

from ROOT import TCanvas,TF1,TGraph
c1 = TCanvas()
gr = TGraph(‘data.txt’)
gr.Draw()
c1.Update()
input()

See the guidelines to see how to post code examples (I edited your post).

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