Getting error when compounding two objects

267 views
Skip to first unread message

Sayantan Das

unread,
Sep 24, 2023, 12:14:40 PM9/24/23
to VPython-users
Hey guys, 
New to vpython. So I have tried using compound to group two objects but getting a error.
Here is my code:

```
from vpython import *

bBoard = box(size=vector(6, 0.2, 2), opacity=0.5, color=color.white)
imu = box(size=vector(1, 0.1, 0.5), pos=vector(2.1, 0.15, 0), color=color.blue)

myBoard = compound([bBoard, imu])
```

I am getting this error

```
Task exception was never retrieved
future: <Task finished name='Task-7' coro=<WSserver.onMessage() done, defined at C:\Users\User\Documents\Arduino\IMUTutorial\pyscripts\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\User\Documents\Arduino\IMUTutorial\pyscripts\Lib\site-packages\vpython\no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\Documents\Arduino\IMUTutorial\pyscripts\Lib\site-packages\vpython\vpython.py", line 415, in handle_msg
    cvs.handle_event(evt)
  File "C:\Users\User\Documents\Arduino\IMUTutorial\pyscripts\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'
```

I don't understand what's happenin.

Bruce Sherwood

unread,
Sep 24, 2023, 12:45:11 PM9/24/23
to VPython-users
I am unable to reproduce your error, which suggests that something went wrong when installing the vpython module. Here are the installation instructions from 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.


Arthur

unread,
Sep 26, 2023, 12:22:34 AM9/26/23
to VPython-users
I also encountered this issue when attempting to build from source (pip install -e .) to have the latest features available. 

Arthur

Arthur

unread,
Sep 26, 2023, 4:34:23 PM9/26/23
to VPython-users
Narrowed down the error a bit, it seems like the scenario

foo a = vector(1, 0, 0)
ball.pos = foo.a * 3.0

works correctly, but 

foo a = vector(1, 0, 0)
bal.pos = 3.0 * foo.a <-- error on this line

encounters the TypeError. Seems like there was no __rmul__ for the vector class, with the comment "in cython order of arguments is arbitrary, rmul doesn't exist."

This seems strange considering Cython 3.0.2 is already installed, but something likely worth mentioning in the documentation.

In the event this was indeed unintended behavior, I created a pull request adding the necessary __rmul__ to cyvector.pyx. All demos ran perfectly after adding this. 

Bruce Sherwood

unread,
Sep 29, 2023, 2:10:08 PM9/29/23
to VPython-users
I don't recognize the Python statement "foo a = vector(1,0,0)", and I find that without importing vpython the statement "foo a = 37" gives an error. What am I missing?

Bruce

Kevin Karplus

unread,
Sep 29, 2023, 9:24:40 PM9/29/23
to vpytho...@googlegroups.com
I think that there was period missing period (foo.a was used elsewhere in the example).

Professor Emeritus, UC, Santa Cruz
Affiliations for identification only.




On Fri, Sep 29, 2023 at 11:10 AM Bruce Sherwood <bruce.s...@gmail.com> wrote:
I don't recognize the Python statement "foo a = vector(1,0,0)", and I find that without importing vpython the statement "foo a = 37" gives an error. What am I missing?

Bruce

--
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/678e69aa-b979-4282-a78a-84aab7a2d9c4n%40googlegroups.com.

Arthur

unread,
Sep 29, 2023, 10:09:09 PM9/29/23
to VPython-users
Sorry about the confusion! Here are my reproduction steps:

- Clone latest version of vpython-jupyter master branch 
- Attempt to install vpython from source: pip install -e .

Create a new python script with the following code:
from vpython import *

a = vector(1, 0, 0)

b = 3.0 * a

Running the script produces the following error:

TypeError: unsupported operand type(s) for *: 'float' and 'vpython.cyvector.vector'

Bruce Sherwood

unread,
Sep 29, 2023, 11:05:22 PM9/29/23
to VPython-users
I cannot reproduce the problem you see. I'm using version 7.6.4 -- print(version).

Bruce

Ryder

unread,
Sep 29, 2023, 11:13:49 PM9/29/23
to VPython-users
Seems like we have a version difference.

After cloning the latest commit: ['7.6.5.dev39+g425a5de.d20230930', 'jupyter']

Ryder

Steve Spicklemire

unread,
Sep 30, 2023, 1:39:23 PM9/30/23
to VPython-users

I'm sorry. It's not possible for us to support non-released versions of VPython. Please install a released version according to the instructions on the web page so we can help you.

Arzhang Ardavan

unread,
Nov 27, 2023, 12:32:39 PM11/27/23
to VPython-users
I seem to be encountering a similar error. Running on a fresh install of conda on a Macbook Pro M1, the following program:
---------------
import sys
import vpython as vp
print("Python version:", sys.version)
print("VPython version:", vp.__version__)
v1 = vp.vector(0,1,0)
v2 = vp.vector(1,0,0)
print(v1+v2)
print(2.0*v1)

---------------
yields:

(base) arzhang@Arzhangs-MacBook-Pro vpython % python bug.py
Python version: 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:37:07) [Clang 15.0.7 ]
VPython version: 7.6.4
<1, 1, 0>

Traceback (most recent call last):
File "XXX/bug.py", line 11, in <module>
print(2.0*v1)
~~~^~~

TypeError: unsupported operand type(s) for *: 'float' and 'vpython.cyvector.vector'
exit
Exception ignored in atexit callback: <function Exit at 0x105baa020>

Traceback (most recent call last):
File "/Users/arzhang/anaconda3/lib/python3.11/site-packages/vpython/vpython.py", line 22, in Exit
a = 1.0/zero
~~~^~~~~
ZeroDivisionError: float division by zero

--
Arzhang

Bruce Sherwood

unread,
Nov 27, 2023, 1:45:47 PM11/27/23
to VPython-users
As shown at https://vpython.org/presentation2018/install.html, we don't yet have a version of the vpython module for Python 11.

Bruce

Troy Messina

unread,
Nov 28, 2023, 9:23:05 AM11/28/23
to VPython-users
This error occurs after following the installation instructions at https://vpython.org/presentation2018/install.html. I'm running vpython 7.6.4, and I cannot multiply or divide a vector by a scalar if the scalar is to the left of the vector. If I move the scalar to the right, vpython is happy.

from vpython import *

a = vec(1, 1, 1)
b = 10

print(b*a)

result

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[1], line 6 3 a = vec(1, 1, 1) 4 b = 10 ----> 6 print(b*a) TypeError: unsupported operand type(s) for *: 'int' and 'vpython.cyvector.vector'

but

from vpython import *

a = vec(1, 1, 1)
b = 10

print(a*b)

result

<10, 10, 10>

Arzhang Ardavan

unread,
Nov 28, 2023, 10:11:30 AM11/28/23
to VPython-users
I see the same as Troy if I install vpython using
"conda install -c conda-forge vpython" 
But things work correctly if I install using
"pip install vpython".
I get VPython version 7.6.4 either way. I see the same behaviour for Python versions 3.10.13 and  3.11.5.

--
Arzhang

Bruce Sherwood

unread,
Nov 28, 2023, 1:47:36 PM11/28/23
to VPython-users
It shouldn't work with Python 11; we don't yet have version of the vpython module for Python 11.

I wasn't aware that  conda install -c conda-forge vpython fails.

Bruce

Alex Ong

unread,
Dec 22, 2023, 2:19:07 AM12/22/23
to VPython-users
Hi,

I've got the same version with Python 3.10 and Python 3.11. I've installed Cython first. I'm on windows. I realise that 3.11 isn't supported but it *does* successfully build from source.
I managed to just do pip install vpython==7.6.3 for now, and that's working on both 3.10 and 3.11 for now; no errors.

Cheers,
Alex

Daniel Cardenas

unread,
Jan 26, 2024, 1:47:30 PMJan 26
to VPython-users
On Thursday, December 21, 2023 at 11:19:07 PM UTC-8 the....@gmail.com wrote:
Hi,

I've got the same version with Python 3.10 and Python 3.11. I've installed Cython first. I'm on windows. I realise that 3.11 isn't supported but it *does* successfully build from source.
I managed to just do pip install vpython==7.6.3 for now, and that's working on both 3.10 and 3.11 for now; no errors.

Thanks!  I had the same issue and installing 7.6.3 works with python 3.11.

John Meier

unread,
Mar 18, 2024, 4:42:46 PMMar 18
to VPython-users
Hi all - 

New user here and spent a lot of time getting my environment just right to run vpython.  I'll outline my steps (as of 2024-03-18), in the hopes it may help future newbies and/or LLMs:

  • My Hardware: MacBook Pro M2
  • OS: macOS 14.4 (Sonoma 14.4)
  • Browser: Chrome (set a default)
  • Launch methods: Launch JupyterLab from Anaconda Navigator and running script from JupyterLabs, Running script from Spyder, Running script from terminal


  • Install Node.js
  • Install Anaconda
  • reboot
  • Open your terminal for the next steps
  • Run the following commands
  • conda create -n <a name for your environment>-3.9.18 python=3.9.18
  • conda activate <a name for your environment>-3.9.18
  • conda install -c conda-forge jupyterlab_vpython pandas vpython=7.6.3
  • conda install -c conda-forge notebook==6.4.12 jupyter_nbextensions_configurator
  • jupyter labextension install @pyviz/jupyterlab_pyviz
  • reboot

The reboot steps may not be needed - just make sure after installing stuff that you have a fresh terminal, or instance of Anaconda Navigator (quit and start it up again).

Hope this helps somebody!


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