PyROOT and Spyder re-running error

Hi, I found a very confusing error(for me) when running pyroot with Spyder.
For example I am able to run:

import ROOT

TwoDGaus=ROOT.TF2("TwoDGaus","([0]*TMath::Gaus(x,[1],[2]))")
TwoDGaus.SetParameter(0,5)
TwoDGaus.SetParameter(1,25)
TwoDGaus.SetParameter(2,1)

h_gaus = ROOT.TH1D("h_gaus", "", 20,-5, 5)
h_gaus.Reset()
h_gaus.FillRandom('gaus',10000)
h_gaus.Draw()

Without problems the first time. But if I try to re-run the script I run in to a error:

runfile('/home/fredrik/Code_python/Gaustest.py', wdir='/home/fredrik/Code_python')
Traceback (most recent call last):

  File "<ipython-input-2-380ebd19039d>", line 1, in <module>
    runfile('/home/fredrik/Code_python/Gaustest.py', wdir='/home/fredrik/Code_python')

  File "/home/fredrik/anaconda2/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 681, in runfile
    __umr__.run(verbose=verbose)

  File "/home/fredrik/anaconda2/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 628, in run
    modpath = getattr(module, '__file__', None)

  File "/home/fredrik/root/lib/ROOT.py", line 215, in __getattr__
    klass = _root.MakeRootClass( attr, cls )

TypeError: requested class 'ROOT::__file__' does not exist

And I have to restart the kernel in order to get it working again for one run then error occurs again.
I am pretty clueless what the error means. Or what it means that I can run it one time and no more without restarting. Help appreciated.

Hi,

can you confirm that you can run the script twice in a vanilla python interpreter to exclude obvious rrot issues?
It would be helpful to know what version of root you are running and why the normal execution is different in spider.

D

Hi,

Yes I can confirm that the complete code wont run twice on a python console or ipython console in Spyder. I am running root 5.34/34. Found I can run the code in a “dedicated python console” in spyder repeatedly. Can also step through the code several times with ipython with out problem. So maybe the problem lies in Spyder? This is not a huge problem now but still it seams strange.

Hi,

it looks like a spider issue. Perhaps something can be found on its documentation.

Cheers,
Danilo

Hi,

that’s not module ROOT, but the namespace ROOT through a lookup of the metaclass of namespace std. What happens is that ROOT.py puts namespaces into sys.modules so that classes can be imported from there. However, these have no file attributes.

Recommend just stuffing one in:import ROOT ROOT.std.__file__ = 'ROOT.std.py'
Cheers,
Wim

Hello, all!

I trying to run the example Jupyter Notebook in the Spyder 2 and I get the same error:

TypeError: requested class 'ROOT::__file__' does not exist

Maybe the file to created the graph is not openning

Someone know how to fix this,

Thanks!
Andre