我一直在学习 Python 物理,我使用 VIDLE - Py 2.7,
我打开一个新文件并且不保存输入以下代码:
从视觉导入 *
scene.width = 800
scene.height = 600
scene.autoscale = 0
scene.range = (100, 100, 100)
scene.center = (0, 40, 0)
#scene.fullscreen = 1
ball = sphere(pos=(0,103,1),radius = 2)
ground = box(pos=(0,-1,0),size=(100,2,100))
building = box(size = (6,100,6),pos=(0,50,0),color=color.blue)
gravity = 9.8 # m/s**2
velocityX = 7 #m/s
seconds = 0
dt = 0.05
finished = False
while not finished:
rate(100) # dont run through loop more than 100 times/sec
seconds += dt
#position equation; y(t) = y0 + v0*t + .5 * a * t**2
ballY = 100 - .5 * gravity * seconds**2
ballX = velocityX * seconds
ball.pos = vector(ballX, ballY, 0)
if ballY -2 <=0:
finished = True
print "seconds to drop: " + str(seconds)
这成功地运行了程序,但是当我将它保存为 .py 然后尝试以同样的方式再次运行它时,我得到一个错误
回溯(最近一次通话最后):文件“/Users/bencallaghan/Desktop/psyre.py”,来自可视化导入的第 1 行 * 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site -packages/VPython-6.05-py2.7-macosx-10.6-intel.egg/visual/ init .py”,第 34 行来自 visual_common.create_display 导入 * 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib /python2.7/site-packages/VPython-6.05-py2.7-macosx-10.6-intel.egg/visual_common/create_display.py”,第 10 行 import wx as _wx 文件“/usr/local/lib/wxPython-2.9 .4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/ init.py”,来自 wx._core 导入的第 45 行 * 文件“/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py ”,第 5 行导入新文件“/Users/bencallaghan/Desktop/new.py”,第 8 行来自 pylab 导入 scatter,xlabel,ylabel,xlim,ylim,show ImportError: No module named pylab
我的猜测是它在 Vpython 中的某种类型的 shell 中运行,可以访问 visual 和 pylab 但是当我保存它然后尝试从其他地方访问它们并且它不能。但除了这个推理之外,我几乎不知道从那里去哪里有什么想法?