【发布时间】:2017-01-23 13:17:49
【问题描述】:
我正在尝试在 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 不兼容(我在某些地方读过)还是有解决方法(我也在其他地方读过)?
谢谢。
【问题讨论】:
-
您是否尝试过在 iPython 终端中运行导入命令?
标签: vpython