【问题标题】:Installing and running vpython with Python 3.5 on Windows 10在 Windows 10 上使用 Python 3.5 安装和运行 vpython
【发布时间】: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


【解决方案1】:

我不记得对 Python 3.5 的确切支持何时可用;现在肯定支持它。但问题可能与程序有许多错误有关。这是一个适用的版本,包括 Windows 10 上的 Python 3.5。更正是更改 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 2018-02-18
    • 2018-04-08
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多