在Windows 10上使用Python 3.5安装和运行vpython

时间:2017-01-23 13:17:50

标签: vpython

我正在尝试在Windows 10上使用python3.5安装vpython。

我在cmd中使用了以下命令:

pip install vpython
pip install update --ipython

如果我然后尝试运行一些vpython代码(从互联网复制以模拟抛射物运动):

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

当我运行此操作时,我会收到以下错误:

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'

我无法理解这里的问题,也无法理解我在网上找到的这个问题。谁能告诉我这里的分数是多少? vpython与python 3.5不兼容(我在某些地方读过)或者是否有解决方法(我在其他地方也读过)?

谢谢。

1 个答案:

答案 0 :(得分:0)

我不记得究竟什么时候支持Python 3.5了。它现在肯定得到支持。但问题可能与程序存在许多错误这一事实有关。这是一个有效的版本,包括在Windows 10上的Python 3.5。更正是真的 - &gt;真的,巴尔

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