vpython compound not working

195 views
Skip to first unread message

Somnath Chakraborty

unread,
Feb 6, 2024, 11:13:03 AMFeb 6
to VPython-users
Hi !


from vpython import *

Xarrow = arrow(axis = vector(2,0,0), color = color.red, shaftwidth = .02)
Yarrow = arrow(axis = vector(0,2,0), color = color.green, shaftwidth = .02)
Zarrow = arrow(axis = vector(0,0,2), color = color.blue, shaftwidth = .02)

Q1 = quad(v0=vertex(pos=vec(0,0,0), color=color.red),
          v1=vertex(pos = vec(1,0,0), color=color.red),
          v2=vertex(pos = vec(1,1,0), color=color.red),
          v3=vertex(pos = vec(0,1,0), color=color.red))

Q2 = quad(v0=vertex(pos=vec(0,0,0), color=color.yellow),
          v1=vertex(pos = vec(1,0,0), color=color.yellow),
          v2=vertex(pos = vec(1,0,1), color=color.yellow),
          v3=vertex(pos = vec(0,0,1), color=color.yellow))

Q3 = compound([Q1,Q2])

while True:
    pass

 
while run above code following error occurred:

Microsoft Windows [Version 10.0.18363.1082]
(c) 2019 Microsoft Corporation. All rights reserved.

F:\Python Programming\VPython>C:/Users/SOMNATH/AppData/Local/Programs/Python/Python311/python.exe "f:/Python Programming/VPython/Test3D.py"
Task exception was never retrieved
future: <Task finished name='Task-7' coro=<WSserver.onMessage() done, defined at C:\Users\SOMNATH\AppData\Local\Programs\Python\Python311\Lib\site-packages\vpython\no_notebook.py:181> exception=TypeError("unsupported operand type(s) for *: 'float' and 'vpython.cyvector.vector'")>
Traceback (most recent call last):
  File "C:\Users\SOMNATH\AppData\Local\Programs\Python\Python311\Lib\site-packages\vpython\no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "C:\Users\SOMNATH\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SOMNATH\AppData\Local\Programs\Python\Python311\Lib\site-packages\vpython\vpython.py", line 415, in handle_msg
    cvs.handle_event(evt)
  File "C:\Users\SOMNATH\AppData\Local\Programs\Python\Python311\Lib\site-packages\vpython\vpython.py", line 3262, in handle_event
    obj._axis.value = obj._size._x*norm(obj._axis)
                      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for *: 'float' and 'vpython.cyvector.vector'

Kindly advise how to remove such error.

Regards

Bruce Sherwood

unread,
Feb 6, 2024, 12:06:37 PMFeb 6
to VPython-users
Apparently you are using Python 3.11, for which there is not yet a working version of the vpython module, though we expect to have a working module very soon. Here are the installation instructions from vpython.org:

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.

Somnath Chakraborty

unread,
Feb 8, 2024, 9:49:05 AMFeb 8
to VPython-users
Dear Sir,
Thank you for your reply. I have now downloaded and install Python 3.9 in C drive under C:\Python 3.9 directory when earlier python 3.11 still in my computer. What are the changes required now to run vPython file kept in my F: drive. Please guide me as I am new to Python programming.
Regards,
Somnath Chakraborty

Bruce Sherwood

unread,
Feb 8, 2024, 1:46:09 PMFeb 8
to vpytho...@googlegroups.com
It is very difficult for me to tell you how to use Python 3.11 because I don't know exactly how you installed Python 3.11.

I will make a guess that you installed Python 3.11 by using the Anaconda distribution. If that is the case, find the terminal program ("Anaconda Powershell") that comes with Anaconda and type  "spyder", which is one of the environments you can use to run Python 3.11. Enter the following simple program as a test:

from vpython import *
box()

You should see a white cube.

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

Also, go to webvpython.org click "Welcome to VPython" for a tutorial on VPython.

There is an alternative to trying to figure out how to run VPython, which is to go to webvpython.org and sign in, in which case you don't have to install Python, which makes things much easier (at webvpython.org your Python program is converted to JavaScript and runs in your browser).

Bruce

Somnath Chakraborty

unread,
Feb 13, 2024, 12:24:25 PMFeb 13
to VPython-users
Dear Sir,
Now "compound" is working in vPython as I installed Python 3.9 version according to your guidance. Thank you once again.  I am now facing problem while coding with Mouse Events in vPython as under:-

from vpython import *

scene.range = 4
sphere() # display a white sphere 

while 1:

if scene.mouse.clicked:

   m = scene.mouse.getclick()

   loc = m.pos

    print(loc)

    sphere(pos=loc, radius=0.1, color=(1,0,0))


while running above code getting following error message

(MyEnv) F:\Python Programming\MyEnv>"f:/Python Programming/MyEnv/Scripts/python.exe" "f:/Python Programming/MyEnv/Test3D2.py"

Traceback (most recent call last):
  File "f:\Python Programming\MyEnv\Test3D2.py", line 7, in <module>
    if scene.mouse.clicked:
AttributeError: 'Mouse' object has no attribute 'clicked'

Task exception was never retrieved
future: <Task finished name='Task-123' coro=<WSserver.onMessage() done, defined at f:\Python Programming\MyEnv\lib\site-packages\vpython\no_notebook.py:181> exception=RuntimeError("can't register atexit after shutdown")>

Traceback (most recent call last):
  File "f:\Python Programming\MyEnv\lib\site-packages\vpython\no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "C:\Python 3.9\lib\asyncio\base_events.py", line 814, in run_in_executor
    executor = concurrent.futures.ThreadPoolExecutor(
  File "C:\Python 3.9\lib\concurrent\futures\__init__.py", line 49, in __getattr__
    from .thread import ThreadPoolExecutor as te
  File "C:\Python 3.9\lib\concurrent\futures\thread.py", line 37, in <module>
    threading._register_atexit(_python_exit)
  File "C:\Python 3.9\lib\threading.py", line 1414, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

Task exception was never retrieved
future: <Task finished name='Task-124' coro=<WSserver.onMessage() done, defined at f:\Python Programming\MyEnv\lib\site-packages\vpython\no_notebook.py:181> exception=RuntimeError("can't register atexit after shutdown")>

Traceback (most recent call last):
  File "f:\Python Programming\MyEnv\lib\site-packages\vpython\no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "C:\Python 3.9\lib\asyncio\base_events.py", line 814, in run_in_executor
    executor = concurrent.futures.ThreadPoolExecutor(
  File "C:\Python 3.9\lib\concurrent\futures\__init__.py", line 49, in __getattr__
    from .thread import ThreadPoolExecutor as te
  File "C:\Python 3.9\lib\concurrent\futures\thread.py", line 37, in <module>
    threading._register_atexit(_python_exit)
  File "C:\Python 3.9\lib\threading.py", line 1414, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

Task exception was never retrieved
future: <Task finished name='Task-125' coro=<WSserver.onMessage() done, defined at f:\Python Programming\MyEnv\lib\site-packages\vpython\no_notebook.py:181> exception=RuntimeError("can't register atexit after shutdown")>

Traceback (most recent call last):
  File "f:\Python Programming\MyEnv\lib\site-packages\vpython\no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "C:\Python 3.9\lib\asyncio\base_events.py", line 814, in run_in_executor
    executor = concurrent.futures.ThreadPoolExecutor(
  File "C:\Python 3.9\lib\concurrent\futures\__init__.py", line 49, in __getattr__
    from .thread import ThreadPoolExecutor as te
  File "C:\Python 3.9\lib\concurrent\futures\thread.py", line 37, in <module>
    threading._register_atexit(_python_exit)
  File "C:\Python 3.9\lib\threading.py", line 1414, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

kindly advise.

regards

Somnath Chakraborty

Bruce Sherwood

unread,
Feb 13, 2024, 1:43:30 PMFeb 13
to VPython-users
There are multiple errors in your program. Here is a working version:

from vpython import *

scene.range = 4
sphere() # display a white sphere

while True:
    m = scene.waitfor('click')
    loc = m.pos
    print(loc)
    sphere(pos=loc, radius=0.1, color=vector(1,0,0))

Bruce

Bruce Sherwood

unread,
Feb 13, 2024, 1:47:51 PMFeb 13
to VPython-users
It looks like you used documentation for  a very old version of VPython. The text at the start of the old documentation page that you apparently used says this:

This is documentation for Classic VPython (VPython 6), which is no longer supported but is provided here as historical material. See vpython.org for information on installing the vpython module or using Web VPython. Documentation is available at webvpython.org by clicking Help. 


Bruce

Somnath Chakraborty

unread,
Feb 29, 2024, 10:04:12 PMFeb 29
to vpytho...@googlegroups.com
Hello Mr Bruce,
I am facing one problem in Vpython. The bounding box is not created in the exact place from the following code in Visual Code, however it is created in the correct place in  Web Python 3.2. What would be the reasons?

image.png

from vpython import *

obj1 = sphere(pos = vector(1,0,0), radius = .5)
obj2 = sphere(pos = vector(-1,0,0), radius = .5)
comp_obj = compound([obj1, obj2])
bb_comp_obj = comp_obj.bounding_box()
print(bb_comp_obj)

for point in bb_comp_obj:
   sphere(radius=.08, pos=point, color =color.yellow)

while True:
   pass










--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vpython-users/fbbf2d99-7247-4a1e-82ef-2b0f30e3ce8bn%40googlegroups.com.

Bruce Sherwood

unread,
Mar 1, 2024, 7:55:49 PMMar 1
to VPython-users
The most likely cause of the problem is that you are using a version of Python newer than 3.10. Below are the current instructions from vpython.org for installing the vpython module. We do expect to release very soon a version of the vpython module that runs with Python 3.11 and 3.12.

Using VPython with installed Python

Somnath Chakraborty

unread,
Mar 2, 2024, 10:17:22 PMMar 2
to vpytho...@googlegroups.com
Good Morning Mr Bruce,
Thanks for your reply. As per your guidance, I installed Anaconda Python Distribution and wrote code through Spider 5 as you can see in the below picture. However, the same problem still exists. Bounding Box created in a different position. Kindly advise what is wrong.
Regards,
Somnath Chakraborty


image.png




















--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.

Bruce Sherwood

unread,
Mar 3, 2024, 6:11:34 PMMar 3
to VPython-users
My apologies: there is indeed a bug in the handling of the bounding box for compounds. I don't know whether the fix will make it into the upcoming release. I guess one thing you could do is display the bounding boxes of each sphere before making the compound, though of course there will be some extra points that you might want to make invisible.

Bruce
Reply all
Reply to author
Forward
Message has been deleted
0 new messages