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


h_gaus = ROOT.TH1D("h_gaus", "", 20,-5, 5)

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/', wdir='/home/fredrik/Code_python')
Traceback (most recent call last):

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

  File "/home/fredrik/anaconda2/lib/python2.7/site-packages/spyderlib/widgets/externalshell/", line 681, in runfile

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

  File "/home/fredrik/root/lib/", 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.


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.



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.


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



that’s not module ROOT, but the namespace ROOT through a lookup of the metaclass of namespace std. What happens is that 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__ = ''

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,