Click "Read more" to view the details of each topic
Using VPython with installed Python

We recommend installing the Anaconda Python distribution.

The vpython module currently works with Python versions 3.8 through  3.12.

The 3D displays are rendered by WebGL in a browser window. For details, see
    https://vpython.org/contents/VPythonArchitecture.pdf

The vpython module is available using
     "conda install -c vpython vpython" or
     "conda install -c conda-forge vpython" or      
     "pip install vpython"

To update to later versions of vpython use
     "conda update -c vpython vpython" or
     "pip install -U vpython"

When running from a terminal, if the program does not end with a loop
containing a rate() statement, you need to add "while True: rate(30)"
to the end of the program. This is not necessary when launching from
environments such as Jupyter notebook, IDLE, or Spyder.

Using the vpython module outside a Jupyter notebook

Read more
You can launch a VPython program from applications such as IDLE, Spyder, or a terminal.

This short program will display a white box on a black background:
    from vpython import *
    box()

Either with or without a Jupyter notebook, "from vpython import *" also imports all math functions, clock(), random(), and arange(). This simplifies moving programs between Web VPython and VPython 7.

In JupyterLab the default is for output to be displayed in a cell that has a very small height, and this includes a VPython display. You can scroll to see other parts of the display, but you may wish to right-click anywhere in the notebook and select "Disable Scrolling for Outputs," in which case VPython displays normally.

In VPython 7.5.0 and later, the following code can be used to shut down a running program:

    from vpython.no_notebook import stop_server
    stop_server()

There is a suite of demo programs for use without a Jupyter notebook (zip file).

The newest Spyder requires using VPython 7.5.0 or later. For older versions of VPython, a simple option is to install the older Spyder 3.1.4 by executing "conda install spyder=3.1.4", though Spyder 3.1.4 doesn't work with Python 3.7, which is what Anaconda now installs. You can start Spyder by clicking the Spyder icon that is installed with Anaconda, or you can start Spyder from a command prompt by typing "spyder". In Spyder you must go to Tools > Preferences > Run and specify "Execute in a dedicated Python console".

Some Mac users have reported that running from Spyder doesn't work. The following workaround, making and invoking a new environment, does work: "conda create -n vpclean -c vpython vpython python=3" followed by "source activate vpclean".

 

 




Using the vpython module in a Jupyter notebook or Jupyter lab

Read more
To use Jupyter lab (version 3 or higher) execute one of these commands:

    pip install jupyterlab-vpython
    conda install -c conda-forge jupyterlab-vpython

To uninstall Jupyter lab, execute one of these commands (depending on whether you installed with pip or conda):

    pip uninstall jupyterlab-vpython
    conda uninstall jupyterlab-vpython

There are two ways to start a Jupyter notebook or lab. In a terminal, execute "jupyter notebook" or "jupyter lab". Or (depending on what operating system you're using), doubleclick the icon "Jupyter Notebook" or "JupyterLab" that is shown as one of the Anaconda-related tools.

If you have a recent release of the Mac operating system, to start the Jupyter notebook you may need to execute this:
    jupyter notebook --browser=Chrome

This short program will display a white box on a black background:
    from vpython import *
    box()

Either with or without a Jupyter notebook or lab, "from vpython import *" also imports all math functions, clock(), random(), and arange(). This simplifies moving programs between Web VPython and VPython 7.

Click in the first cell (containing the vpython import statement), then click the run icon, the one that is a rightward-facing triangle touching a vertical line. Currently, to re-run a VPython program 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. Some users find it convenient to include in the first cell just these statements:

    from vpython import*
    scene = canvas()

Then put the rest of the program in later cells. The result is that the 3D display will be shown just under the first cell instead of at the end of the last cell. It also ensures that the vpython module has been fully initialized before continuing. Moreover, you can re-run the program more easily.

There is a suite of demo programs for use with a Jupyter notebook or JupyterLab (zip file).

There is a Binder package of some demo programs, which lets you run Jupyter VPython programs even on computers or mobile devices that do not have Python installed. Here is an explanation of the Binder mechanism. Because the Binder servers are shared among a large number of people, performance can vary a great deal from day to day and from hour to hour.

    







French translation by Samuel Badree

Albanian translation by Sarah Margot McMason and Ermira McMason

Azerbaijani translation of this page by Qalina Najafova