2017-01-23 5 views
0

Ich versuche, auf Fenster mit python3.5 zu installieren VPython 10.Installieren und Ausführen VPython mit Python 3.5 auf 10 Windows-

benutzte ich die folgenden Befehle in der cmd:

pip install vpython 
pip install update --ipython 

Wenn ich dann versuchen, einige VPython Code (kopiert aus dem Internet Wurfbewegung zu simulieren) auszuführen:

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 

Als ich dies laufe ich dann die folgenden Fehlermeldungen erhalten:

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' 

Ich kann das Problem hier nicht verstehen, noch kann ich die Diskussionen, die ich online gefunden habe, verstehen. Kann mir jemand sagen, wie das Ergebnis hier ist? Ist vpython inkompatibel mit Python 3.5 (welches ich an einigen Stellen gelesen habe) oder gibt es eine Problemumgehung (die ich auch an anderen Stellen gelesen habe)?

Vielen Dank.

+0

Haben Sie versucht, den Importbefehl in einem iPython-Terminal auszuführen? –

Antwort

0

Ich kann mich nicht erinnern, wann genau Unterstützung für Python 3.5 verfügbar wurde; es wird jetzt sicher unterstützt. Das Problem könnte jedoch mit der Tatsache zusammenhängen, dass das Programm eine Reihe von Fehlern aufweist. Hier ist eine Version, die funktioniert, einschließlich mit Python 3.5 auf Windows 10. Die Korrekturen sollten sich ändern -> 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 
Verwandte Themen