NameError when trying to create sphere in Jupyter

425 views
Skip to first unread message

Chris Fink

unread,
Feb 29, 2016, 9:21:59 PM2/29/16
to VPython-users
I am new to VPython, but have some experience with Python, so I decided to jump right in and use Jupyter. I used Anaconda to install Python 3.5, VPython, and Jupyter on Windows 7, and I'm having some trouble with the most basic application of VPython within Jupyter.

I start out by typing the line from vpython import *, then evaluate that cell. Then I type sphere(), and evaluate that cell, and an image of a sphere comes up (so far so good). Then I click the circle arrow to “restart the kernel,” I re-evaluate the first cell (importing vpython), and then I change the second cell to sphere(pos=vec(1,0,0)). When I try to evaluate the second cell, I get the following error:

 

NameError                                 Traceback (most recent call last)

<ipython-input-1-65100377a774> in <module>()

----> 1 sphere(pos=vec(1,0,0))

 

NameError: name 'sphere' is not defined


Here is a screen shot:


















Thanks in advance for the help!


Bruce Sherwood

unread,
Feb 29, 2016, 10:47:36 PM2/29/16
to VPython-users
I wasn't able to see the behavior you see, but I find that if I click the circular arrow, then as quickly as possible run the first cell and then the second, often no canvas appears. No error, but no display, and the highlighted cell is cell 3.

Next I combined the two cells. With the combined cell highlighted, I click the circular arrow, and then hit the run button. If I wait to see the signals "Restarting kernel" followed by "Kernel ready", I see the canvas and the sphere. If I don't wait, there is no canvas (and no sphere).

Bottom line: It seems to be important to wait for the "Kernel ready" before doing anything.

I may have mentioned this before: In the latest version of Jupyter there is a "command palette" that includes "restart kernel and run all cells", and it seems to avoid the problem, presumably because it waits for "Kernel ready" before running the program. Unfortunately there isn't a keypress shorthand for this.

If you wait for "Kernel ready", do you still see the problem?

Chris Fink

unread,
Mar 1, 2016, 11:11:19 AM3/1/16
to VPython-users
Thanks, Bruce, putting both lines in the same cell and using "restart kernel and run all cells" solved the problem. I appreciate it!
Reply all
Reply to author
Forward
0 new messages