-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No interactive ROOT Canvas with qtconsole & ROOT 6 #780
Comments
Hi I ran into a similar problem, which is not related to JupyROOT. The example from phi-man reduced to the essential:
will give the output:
If you remove the import rootpy.plotting, it works! So there is something happening in the include, which is not supposed to happen. |
Might be a related issue: import rootpy.ROOT as ROOT
import rootpy.plotting
ROOT.Canvas() doesn't create a pop-up canvas as import rootpy.ROOT as ROOT
ROOT.Canvas() does create a pop-up canvas. Similar issues happens whenever I try to import some modules inside rootpy ( |
Just a workaround, based on the previous post: import rootpy.ROOT as ROOT
ROOT.Canvas().Close()
import rootpy.plotting Seems if the GUI is properly initialised (after the ROOT import and creation of one canvas), then afterwards everything works. |
I've started investigating of this issue. This has indeed something to do with ROOT version, both python2 and python3 show similar behaviour with ROOT 6. rootpy/rootpy/plotting/__init__.py Line 11 in 457e074
This won't make dear TF[1-3] functions very happy 😄 but after this rootpy's finalSetup() won't activate a batch mode anymore. After further investigation I've found that problem lies in decorators.py file, namely line Line 141 in 457e074
When inspector.getmembers() gets called for F1, F2, F3 something happans and batch mode gets activated (which can't be reverted after this). I kinda found a solution for this problem, which involves dirty modification of inspector.getmembers() function and fixes the problem without hurting anything. This is better than having an mandatory import from PyROOT just for drawing, but still not the best one. Besides that, as much as I know in python3 using inspector.getmembers() method to get all the class members can cause problems too. Anyway I can try to make a PR with my "dirty" solution or probably someone can propose a better idea?
BTW #782 should be related with this issue too. |
As this topic is still discussed, I would like to show you my solution: If I remember correctly, the error is originally caused by the TCanvas::Init() function, which is called in every canvas constructor. Both, pyroot as well as rootpy activate the batch mode if they detected an interactive jupyter session. In addition, some of the rootpy modules (e.g. rootpy.plotting) led to a Canvas being constructed (and consequently Init() being called). The problem with the TCanvas::Init routine arises if it get firstly called in batch mode (doing its init stuff within this state) and later on "real" canvases are requested to be drawn. So you have to ensure by all means that the init part is also done in interactive mode. In my specific case even my rootlogon.C led to such a call, which is why I ended up with this rather complicated startup routine: During jupyter kernel startup/header of your python script
and my rootlogon.py (which, in turn, is calling my rootlogon.C):
Btw, it took me some time to get ROOT's interactive mode back to work when used with newer root versions. To be more precise, I had to combine the event-loop of the ROOT framework with the one from the jupyter qtconsole/notebook. Did you encounter a similar problem and how did you solve it? |
@phi-mah You are absolutely correct and this is also more general and not related with jupyter only. The question is why does batch mode get activated without asking for it? Temporary solution could be what you did, i.e triggering PyROOT's version of rootpy/rootpy/plotting/__init__.py Line 11 in 457e074
and without complicated setups and worrryng about the import order in your code, everything should work fine. But again, as I said this makes rootpy's |
I like to work with rootpy (great piece of work btw) within a jupyter qtconsole. As JSROOT still misses some features and I prefer drawables to be displayed in popup-windows rather than inline, I still rely on the classical ROOT canvases.
With ROOT 5.36/36 the following script brings up such a canvas -- thanks to rootpy it can be used interactively:
However this is not possible with newer ROOT Versions, e.g. ROOT 6.10/06
I suppose this to be related to the notebook features added to core ROOT 6. Now, not only rootpy but also JupyROOT both are trying to "catch the canvas" to be drawn, which results in above exception.
But it would be so nice to get the workflow outlined above back to rootpy also when run in conjunction with ROOT 6.
Btw, how does rootpy deals with features that are making it into core ROOT in general? E.g. the drawing of histograms/canvases as png images within an interactive jupyter session. I met it as first in rootpy, but nowadays it seems to be adapted by JupyROOT?
Once again, I really like rootpy -- many thanks for providing it to the community!!
The text was updated successfully, but these errors were encountered: