AttributeError: module 'vpython' has no attribute 'quaternion'

32 views
Skip to first unread message

Nickey Diorio

unread,
Jun 2, 2025, 7:38:08 PMJun 2
to VPython-users
Howdy Everyone,

I am getting a pretty specific error of "AttributeError: module 'vpython' has no attribute 'quaternion'" across multiple computers and python installations(3.9-3.13). Despite my troubleshooting efforts, I have not been able to resolve it. I have identified that vpython is correctly installed on each environment and could successfully interact with it (incredbily simplified test code below). Please let me know if anyone has encountered this issue. Thank you!
INPUT:
print("Starting VPython test...")
problem_found = False
try:
    import vpython as vp
    print(f"Successfully imported vpython as vp.")
except ImportError as e:
    print(f"CRITICAL: Failed to import vpython: {e}")
    problem_found = True

if not problem_found:
    try:
        version_info = "N/A"
        if hasattr(vp, '__version__'):
            version_info = vp.__version__
        print(f"VPython version: {version_info}")
    except Exception as e:
        print(f"Error accessing VPython version: {e}")
        problem_found = True

if not problem_found:
    try:
        print("Attempting to create vp.vector(1,2,3)...")
        v = vp.vector(1,2,3)
        print(f"Successfully created vp.vector: {v}")
    except AttributeError as e:
        print(f"ATTRIBUTE_ERROR during vp.vector creation: {e}")
        problem_found = True

# Crucial Test Point for quaternion
if not problem_found:
    try:
        print("Attempting to access the vp.quaternion attribute itself (to see if it even exists)...")
        quat_class_ref = vp.quaternion # This line just tries to access the attribute
        print(f"Successfully accessed vp.quaternion. Type: {type(quat_class_ref)}")

        print("Attempting to create vp.quaternion() instance...")
        q = vp.quaternion() # This line tries to instantiate it
        print(f"Successfully created vp.quaternion instance: {q}")
    except AttributeError as e:
        print(f"ATTRIBUTE_ERROR related to vp.quaternion: {e}")
        problem_found = True

OUTPUT:
VPython version: 7.6.5
Attempting to create vp.vector(1,2,3)...
Successfully created vp.vector: <1, 2, 3>
Attempting to access the vp.quaternion attribute itself (to see if it even exists)...
ATTRIBUTE_ERROR related to vp.quaternion: module 'vpython' has no attribute 'quaternion'

John

unread,
Jun 3, 2025, 12:09:11 AMJun 3
to VPython-users
I performed a search for "quaternion" in this forum and found this message from 2019. I think you need to add a quaternion class to your program, maybe import a python package that contains a quaternion class. Maybe something like this.

https://pypi.org/project/Quaternion/

" Many thanks to "bauen1" for submitting an important improvement to the VPython 7 vector class. He wanted to be able to use the vector class in the presence of a quaternion class that permits multiplication of a vector by a quaternion. His changes don't affect the existing use of the vector class.

He used a mechanism that was unfamiliar to me. Python now has a special constant "NotImplemented" which is now returned from the vector class if (for example) you try to multiply a vector times a quaternion. When this happens, Python passes the issue to the quaternion class, if there is one. If there isn't such a class, Python gives an error explaining that one cannot multiply a vector times the second quantity.

A simpler case if vector plus a number, in which case Python finds that neither the vector class nor the number class can deal with this and gives an error exaplainging that you can't add a vector and a number.

This will take effect in the next release of VPython 7.

Bruce
"

John
Reply all
Reply to author
Forward
0 new messages