Getting an error when running import vpython, can someone help me out?

169 views Asked by At

Installed vpython via cmd: c:\Users>pip install vpython

Using Python 3.9.9

After installation I tested in cmd using python -m vpython.test and got the following error:

PS H:\Preston\folders\programming\py\vpython> python -u "h:\Preston\folders\programming\py\vpython\intro.py"

exit

Error in atexit._run_exitfuncs:
Traceback (most recent call last):

  File "C:\Users\Preston\AppData\Local\Programs\Python\Python39\lib\site-packages\vpython\vpython.py", line 22, in Exit

    a = 1.0/zero

ZeroDivisionError: float division by zero
2

There are 2 answers

6
NADJI On BEST ANSWER

The error is not in the import the code works fine, but if you read the error "ZeroDivisionError: float division by zero" your code is dividing by zero try to change your code to something like if(zero==0): print("this is mathematically wrong") else: a = 1.0/zero

1
user1114907 On

From the installation instructions at vpython.org:

Using VPython with installed Python We recommend installing the Anaconda Python distribution.

The vpython module currently works with Python versions 3.8, 3.9, and 3.10.

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 "conda install -c conda-forge/label/cf202003 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.