Skip to main content

VPython for Jupyter Notebook

Project description


This package enables one to run VPython in a browser, using the GlowScript VPython API, documented in the Help at If the code is in a cell in a Jupyter notebook, the 3D scene appears in the Jupyter notebook. If the code is launched outside a notebook (e.g. from the command line), a browser window will open displaying the scene.

VPython makes it unusually easy to create navigable real-time 3D animations. The one-line program "sphere()" produces a 3D sphere with appropriate lighting and with the camera positioned so that the scene fills the view. It also activates mouse interactions to zoom and rotate the camera view. This implementation of VPython was begun by John Coady in May 2014. Ruth Chabay, Matt Craig, and Bruce Sherwood are assisting in its further development.


For more detailed instructions on how to install vpython, see, where you will also find a link to the VPython forum, which is a good place to report issues and to request assistance.


  • If you use the anaconda python distribution, install like this: conda install -c vpython vpython
  • If you use any other python distribution, install this way: pip install vpython

Sample program

Here is a simple example:

from vpython import *

This will create a canvas containing a 3D sphere, with mouse and touch controls available to zoom and rotate the camera:

Right button drag or Ctrl-drag to rotate "camera" to view scene.
To zoom, drag with middle button or Alt/Option depressed, or use scroll wheel.
     On a two-button mouse, middle is left + right.
Shift-drag to pan left/right and up/down.
Touch screen: pinch/extend to zoom, swipe or two-finger rotate.

Currently, to re-run a VPython program in a Jupyter notebook you need to click the circular arrow icon to "restart the kernel" and then click the red-highlighted button, then click in the first cell, then click the run icon. Alternatively, if you insert "scene = canvas()" at the start of your program, you can rerun the program without restarting the kernel.

Run example VPython programs: Binder

vpython build status (for the vpython developers)

Build Status Build status

Working with the source code

Here is an overview of the software architecture:

The vpython module uses the GlowScript library (vpython/vpython_libraries/glow.min.js). The GlowScript repository is here:

In the GlowScript repository's docs folder, GlowScriptOverview.txt provides more details on the GlowScript architecture.

Here is information on how to run GlowScript VPython locally, which makes possible testing changes to the GlowScript library:

If you execute, and change the statement "if True:" to "if False", you will generate into the ForInstalledPython folder an un-minified glow.min.js which can be copied to site-packages/vpython/vpython_libraries and tested by running your test in (say) idle or spyder. (Running in Jupyter notebook or Jupyterlab requires additional fiddling.)

Note that in site-packages/vpython/vpython_libraries it is glowcomm.html that is used by launchers such as idle or spyder; glowcomm.js is used with Jupyter notebook (and a modified version is used in Jupyterlab).

Placing console.log(....) statements in the GlowScript code or in the JavaScript section of glowcomm.html can be useful in debugging. You may also need to put debugging statements into site-packages/vpython/

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for vpython, version 7.5.1
Filename, size File type Python version Upload date Hashes
Filename, size vpython-7.5.1-cp36-cp36m-macosx_10_7_x86_64.whl (3.6 MB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size vpython-7.5.1-cp37-cp37m-macosx_10_7_x86_64.whl (3.6 MB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size vpython-7.5.1-py3.7-linux-x86_64.egg (3.8 MB) File type Egg Python version 3.7 Upload date Hashes View hashes
Filename, size vpython-7.5.1.tar.gz (3.6 MB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page