0

I'm trying to install vpython with python3.5 on windows 10.

I used the following commands in the cmd:

pip install vpython
pip install update --ipython

If I then try to run some vpython code (copied from internet to simulate projectile motion):

from vpython import *
from math import sin, cos

initialHeight = 4.6
initialVelocity = 24
Angle = 65

#Set up the display window
scene1 = display(title = "Projectile Motion for the uninitiated",
                x=0,y=0, width=800, height=600,
                range=10, background=colour.white,
                center = (10,initialHeight,0))

#Create objects
table = box(pos=(-1,initialHeight - 1,0), size=(5,1,4))
ball1 = sphere(pos=(0,initialHeight,0),radius=1,
              color=color.green, make_trail = true)

ball2 = sphere(pos=(0,initialHeight,0),radius=1,
              color=color.red, make_trail = true)

floor = box(pos=(0,0,0), size =(100,0.25,10))

t=0
dt=0.01
g=-32 #ft/s**2

Fgrav = vector(0,g*dt,0)

#velocity vector for ball1
ball1v = vector(initialVelocity*cos(Angle*pi/180),
                initialVelocity*sin(Angle*pi/180),0)

#This loop puts it into motion
while True:
    rate(30) #speeds it up
    ball1v = ballv + Fgrav
    ball1.pos += ball1.v*dt

    ball2.pos = (initialVelocity*cos(Angle*pi/180)*t,
                 initialHeight + initialVelocity*t*sin(Angle*pi/180) - 16*t**2)
    if ball1.y < 0: #when ball hits floor
        print("ball1.pos = ", ball1.pos, "t = ", t)
        print("ball2.pos = ", ball2.pos, "t = ", t)
        break

When I run this I then get the following errors:

Traceback (most recent call last):


 File "C:/Users/yours_truly/Google Drive/Python/projectile motion.py", line 1, in <module>
    from vpython import *
  File "C:\Users\yours_truly\AppData\Local\Programs\Python\Python35-32\lib\site-packages\vpython\__init__.py", line 10, in <module>
    from .vpython import *
  File "C:\Users\yours_truly\AppData\Local\Programs\Python\Python35-32\lib\site-packages\vpython\vpython.py", line 442, in <module>
    get_ipython().kernel.comm_manager.register_target('glow', GlowWidget)
AttributeError: 'NoneType' object has no attribute 'kernel'

I cannot understand the problem here, nor can I make sense of the discussions of this that I have found online. Can anyone tell me what the score is here? Is vpython incompatible with python 3.5 (which I've read in some places) or is there a workaround (which I've also read in other places)?

Thank you.

user11128
  • 295
  • 1
  • 2
  • 12

1 Answers1

0

I cannot remember when exactly support for Python 3.5 became available; it is certainly supported now. But the problem may have been associated with the fact that the program has a number of errors. Here is a version that works, including with Python 3.5 on Windows 10. The corrections were to change true -> True, bal

from vpython import *
from math import sin, cos

initialHeight = 4.6
initialVelocity = 24
Angle = 65

#Set up the display window
scene1 = display(title = "Projectile Motion for the uninitiated",
                x=0,y=0, width=800, height=600,
                range=10, background=color.white,
                center = (10,initialHeight,0))

#Create objects
table = box(pos=vec(-1,initialHeight - 1,0), size=vec(5,1,4))
ball1 = sphere(pos=vec(0,initialHeight,0),radius=1,
              color=color.green, make_trail = True)

ball2 = sphere(pos=vec(0,initialHeight,0),radius=1,
              color=color.red, make_trail = True)

floor = box(pos=vec(0,0,0), size =vec(100,0.25,10))

t=0
dt=0.01
g=-32 #ft/s**2

Fgrav = vector(0,g*dt,0)

#velocity vector for ball1
ball1v = vector(initialVelocity*cos(Angle*pi/180),
                initialVelocity*sin(Angle*pi/180),0)

#This loop puts it into motion
while True:
    rate(30) #speeds it up
    ball1v = ball1v + Fgrav
    ball1.pos += ball1v*dt
    ball2.pos = vec(initialVelocity*cos(Angle*pi/180)*t,
                 initialHeight + initialVelocity*t*sin(Angle*pi/180) - 16*t**2,0)
    if ball1.pos.y < 0: #when ball hits floor
        print("ball1.pos = ", ball1.pos, "t = ", t)
        print("ball2.pos = ", ball2.pos, "t = ", t)
        break
user1114907
  • 972
  • 8
  • 15