nengo / nengo-gui

Nengo interactive visualizer
Other
99 stars 38 forks source link

__file__ is not defined #361

Closed drasmuss closed 7 years ago

drasmuss commented 9 years ago

When I open nengo_gui via

import nengo_gui
nengo_gui.Viz(__file__).start()

it opens up the GUI fine, and the model loads properly. But then if I trigger a reload (e.g. by changing the file), I get this error:

Traceback (most recent call last):
  File "...\nengo_gui\nengo_gui\components\netgraph.py", line 64, in _reload
    exec(code, locals)
  File "<string>", line 77, in <module>
NameError: name '__file__' is not defined

So it seems like the global __file__ doesn't exist when you exec the code like that. This is probably something specific to my setup (it seems like it would have been noticed before if it wasn't).

Edit: to be clear, line 77 is the nengo_gui.Viz(__file__).start() line

tbekolay commented 9 years ago

I've gotten this error in the past, and the fix was to put this in a if __name__ == '__main__' block. There was a PR to change this though... I think the exec is in a try / except in which the except has no qualification so the NameError should be caught by that. I'll try to reproduce.

xchoo commented 9 years ago

Does passing the local locals into the constructor fix the problem?

nengo_gui.Viz(__file__, locals=locals(), interactive=False).start()
tcstewar commented 9 years ago

Weird... it's supposed to be filling in __file__ automatically for exactly this reason:

https://github.com/nengo/nengo_gui/blob/master/nengo_gui/viz.py#L203

Oh, oops, I see... it's not doing that in the netgraph.py reload case. That same line should be added there.

tcstewar commented 7 years ago

This has been working for a while (since the server refactoring), so I'm closing this.... :)