vpython runs forever in Jupyter notebook

108 views
Skip to first unread message

Michael Panzer

unread,
Dec 2, 2024, 2:12:20 AM12/2/24
to VPython-users
I am trying to use vpython to create animations from a jupyter notebook but when I run any vpython code the cell never finishes running. I have no issues using vpython in python files so I'm kinda stumped. 
Screenshot 2024-12-01 210929.png

John

unread,
Dec 2, 2024, 3:22:15 PM12/2/24
to VPython-users
What versions of python and Jupyter notebook are you using? Which python IDE are you using? 

You can also try the following code

from vpython import *
scene = canvas()
sphere()

Or try adding a loop that ends. This code will run for 10 seconds in a notebook cell.

from vpython import *
scene = canvas()
sphere()
i = 0
while i < 300:
    rate(30)
    i += 1

Michael Panzer

unread,
Dec 2, 2024, 4:12:27 PM12/2/24
to VPython-users
I am using python 3.12.4 in VS Code. I tried both of those programs and they give the same result as before. I think its getting stuck when creating the sphere object. 

John

unread,
Dec 2, 2024, 5:07:51 PM12/2/24
to VPython-users
To run vpython in a jupyter notebook you need to use notebook version 7.x . I don't think the version of jupyter notebook in vs code is version 7.x. You can however run vpython in vs code without the jupyter notebook as shown in this tutorial video.


It shows how to get started running vpython in no_notebook mode in visual studio code in the first 15 minutes of the video with a demo. I am not sure if the jupyter notebook in visual studio code supports vpython. If vscode is not using jupyterlab version 4.x   or notebook version 7.x then it probably won't work. Also make sure you are using the latest release of vpython which is version 7.6.5. 

If you can't get that to work and you want to run vpython in a desktop app you can try installing the JupyterLab Desktop App which works with vpython. 


Michael Panzer

unread,
Dec 19, 2024, 9:05:47 PM12/19/24
to VPython-users
I took a break for a couple weeks to study for finals but now I'm back at it. 

I have had no issues using vpython in Python files, but for my project I really like the format of a notebook. I double checked the versions of everything you mentioned and I have jupyterlab 4.2.5, notebook 7.2.2, and vpython 7.6.5. 

I found that if I run the notebooks directly through jupyter lab I don't experience the same issues so it's something to do with how vscode implements jupyter notebooks. If I ever find a solution I'll be sure to post it here but for now I will just make do. 

John

unread,
Dec 20, 2024, 7:19:45 PM12/20/24
to VPython-users
The vscode jupyter extension can be found on github here.

https://github.com/microsoft/vscode-jupyter?tab=readme-ov-file

I don't use vscode so I am not familiar with how this extension works. Since VPython is an extension to jupyterlab, you can try using some other jupyterlab extension to see if it works in vscode.

https://jupyterlab.readthedocs.io/en/stable/user/extensions.html

https://saturncloud.io/blog/top-33-jupyterlab-extensions-2024/

Also, as a side note, google colab 

https://colab.research.google.com

uses an older version of notebook ( 6.5.5) so vpython doesn't work there either. I think they use their own proprietary notebook. Maybe vscode has their own proprietary jupyter notebook and are not using the official jupyter notebook version.
Reply all
Reply to author
Forward
0 new messages