Trouble with nengo_gui

Dear Colleagues,

I am having a bit of a problem trying to load the GUI from within a python script. I am new to python, I cannot make sense of the error message and I wonder if it’s related to my setup rather than the GUI itself. I am using a Windows machine with Spyder 4.0.1 and Python 3.7. (I don’t do Jupyter and notebooks.)

After I interrupt the Spyder run with Ctrl+C it seems that port 8080 is stuck so when I try to run the same script from the command line (Anaconda PowerShell Prompt) the browser window is blank. I have to quit Spyder and run the script from the command line to load the GUI.

If I am doing something terribly wrong somewhere would you please point me to the doc page?

The code implements the single neuron demo from HBB.

"""
example 1 chapter 1 of Eliasmith's How to Build a Brain
single neuron model based on a script by s72sue available at
https://github.com/s72sue/Nengo2-Tutorials/tree/master/chapter1
"""
import numpy as np                                  # numerical methods
import nengo                                        # nengo itself
model = nengo.Network( label = 'Single Neuron' )
with model:
    cos = nengo.Node( lambda t: np.cos( 16 * t ) )
    neuron = nengo.Ensemble( 1, dimensions = 1, encoders = [[1]] )
    nengo.Connection( cos, neuron )
import nengo_gui
nengo_gui.GUI(__file__).start()

and the full copy of my console is

Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.12.0 -- An enhanced Interactive Python.
runfile('C:/Bogdan_root/01_Research/01_VisSidus/09_Neural_engineering/Sims/Nengo_tutorials/H2BB_chapter_1/tutorial1.py', wdir='C:/Bogdan_root/01_Research/01_VisSidus/09_Neural_engineering/Sims/Nengo_tutorials/H2BB_chapter_1')
Starting nengo server accessible at:
  http://localhost:8080/?token=4174ecc2def285a5b0827337c8281bfb76733dcd1727d1bc
Exception in thread Thread-7:
Traceback (most recent call last):
  File "C:\Users\bogey\Anaconda3\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\bogey\Anaconda3\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
TypeError: open() takes from 1 to 3 positional arguments but 77 were given
Shutting down server...
Traceback (most recent call last):
  File "C:\Bogdan_root\01_Research\01_VisSidus\09_Neural_engineering\Sims\Nengo_tutorials\H2BB_chapter_1\tutorial1.py", line 40, in <module>
    nengo_gui.GUI(__file__).start()
  File "C:\Users\bogey\Anaconda3\lib\site-packages\nengo_gui\gui.py", line 197, in start
    super(GUI, self).start()
  File "C:\Users\bogey\Anaconda3\lib\site-packages\nengo_gui\gui.py", line 130, in start
    self.server.serve_forever(poll_interval=0.02)
  File "C:\Users\bogey\Anaconda3\lib\site-packages\nengo_gui\server.py", line 238, in serve_forever
    r, _, _ = select.select(sockets, [], [], poll_interval)
KeyboardInterrupt

This appear to be a bug in Nengo GUI. I have made a fix for it here. If you happen to be using a developer installation of Nengo GUI (i.e., if you have used git clone) then you can pull and switch to the fix-start branch and it should now work. If you aren’t using a developer installation, then you can either modify the gui.py file manually (it will be in site-packages/nengo_gui/gui.py; the location of the site-packages directory depends on how you installed Nengo GUI) with the change here or you can switch to a developer installation by doing something this:

pip uninstall nengo-gui
git clone https://github.com/nengo/nengo-gui
cd nengo-gui
git checkout fix-start
pip install -e .

Sorry about the bug; hopefully this is enough to fix it for you but let me know if you run into any issues!

Hi Trevor. Thank you for the prompt reply and there’s no reason to apologize, it’s all part of my learning experience. I have modified gui.py manually and it all works as expected now. I’ll post updates if I encounter any problems.

I have a (naive) question related to the forum posts. When I posted the code and console capture my post looked much less organized and syntax highlighted than it is now. Have you prettified it or is there an automated process that does it for us? Thanks again.

1 Like

I prettified it manually. I find the toolbar on the editor is not great as none of the buttons will format code blocks well, which I find is easiest with three backticks on a line before and after the code block. The toolbar inserts four spaces before each line, but since the text is not monospaced it’s hard to indent code correctly that way. There also isn’t a great reference for the syntax accepted here, but it does accept common markdown.

Thank you. Common markdown it is.