Re: spyder can't recognize vpython module

1,628 views
Skip to first unread message

anatoly techtonik

unread,
Jul 24, 2012, 4:25:08 AM7/24/12
to spyd...@googlegroups.com
Is the problem that you can not run this script with Spyder? Have you tried adding vpython libs to PYTHONPATH? Can you run it with plain Python from command line?

On Tuesday, July 24, 2012 8:26:34 AM UTC+3, pai wrote:
I'm have installed Python(x,y)-2.7.2.3 on Win7 32-bit system to draw a simple 3D animation with vpython module.  The script is shown as following, but the spyder complains with an exclamation mark at the first line of the script and hint shows that 'from visual import *' used; unable to detect undefined names.  The script runs pretty well in IDLE, so I'm sure the problem came from spyder.  Can anyone helps me, please ?



from visual import *

floor = box (pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)

ball = sphere (pos=(0,4,0), radius=1, color=color.red)

ball.velocity = vector(0,-1,0)

dt = 0.01

while 1:

  rate (100)

  ball.pos = ball.pos + ball.velocity*dt

  if ball.y < ball.radius:

    ball.velocity.y = abs(ball.velocity.y)

  else:

    ball.velocity.y = ball.velocity.y - 9.8*dt

David

unread,
Jul 24, 2012, 11:36:54 PM7/24/12
to spyd...@googlegroups.com
The message you reported is just a warning, you can ignore it if you want. Did you actually try running the script?

The reason for the warning is the line "from visual import *", which imports a whole bunch of things from the library, which spyder doesn't know about. This means that spyder's code cannot do clever things like detecting whether you have called an undefined function and displaying a warning about it in the editor.

pai

unread,
Jul 25, 2012, 2:04:17 AM7/25/12
to spyd...@googlegroups.com
As you have proposed, I modified the first line to: 
from visual import box, sphere, color, vector, rate
This lead to a clean script without any spyder warning and a successful run, and only ONE.  When I tried to rerun the script by pressing F5, nothing happen.  My conclusion is maybe spyder isn't friendly enought to some modules, such as Vpython.


在 2012年7月25日星期三UTC+8上午11时36分54秒,David写道:

pai

unread,
Jul 25, 2012, 2:06:30 AM7/25/12
to spyd...@googlegroups.com
The script runs pretty well in IDLE, so I'm sure the problem came from spyder.  Thanks for the hints



在 2012年7月24日星期二UTC+8下午4时25分08秒,anatoly techtonik写道:

Pierre Raybaut

unread,
Jul 28, 2012, 4:39:12 PM7/28/12
to spyd...@googlegroups.com
As David implied, the fact that you changed the import statement
(getting rid of the ugly "import *") has nothing to do with the fact
that your script is executed successfully or not. This warning message
is just about Python programming guidelines, that's all.

Now, I've tried to run this script as I have both VPython and Spyder
installed, and the program runs smoothly, as many times as I want with
both Spyder v2.1.10 and v2.2.0dev. In other words, I can't reproduce
this bug.

Note: for my tests, I ran the script in a dedicated interpreter. If
you are trying to rerun the script again and again in the same
interpreter, then it's normal that the interpreter quits after its
first execution (it's related to VPython internals). Don't forget that
VPython is tweaking IDLE to make some things work (I don't really know
the details, I just remember seing a patch for IDLE in VPython
installer).

HTH,
Pierre

2012/7/25 pai <butc...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "spyder" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/spyderlib/-/3JCmBhxH5mYJ.
>
> To post to this group, send email to spyd...@googlegroups.com.
> To unsubscribe from this group, send email to
> spyderlib+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/spyderlib?hl=en.
Reply all
Reply to author
Forward
0 new messages