Vpython 7 and visual calls no longer work.

1,149 views
Skip to first unread message

john hanly

unread,
Oct 19, 2017, 12:42:44 PM10/19/17
to VPython-users
I'm working thru some python examples in a book. Many of the codes listed calls for a module visual. I believe visual was installed in older versions of Vpython. I am running Python 3.6 with Vpython 7 installed. I use a Mac computer. Many of the sample codes start with lines such as the following: 

     from visual import *                  
     from visual.graph import *
     from visual.graph import gdisplay, gcurve
     from visual.controls import slider, controls, toggle

I learned from an internet search to replace the first line with:

    from vpython import *

This doesn't work for other visual calls. My programs keep crashing because no module visual is found. Is there a way to get these calls to work?

Aaron Titus

unread,
Oct 19, 2017, 3:25:12 PM10/19/17
to vpytho...@googlegroups.com
In VPython 7, you don’t have to import the graph module. You should only need one import statement:

from vpython import *

What book are you using?

AT

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

john hanly

unread,
Oct 19, 2017, 4:25:17 PM10/19/17
to VPython-users
i'm using the "Computational Physics" e-book by Landau, Paez and Bordelanu.

john hanly

unread,
Oct 19, 2017, 4:29:14 PM10/19/17
to VPython-users
I tried removing the import visual commands but i got error messages and message that slider, controls and toggle commands do not exist.


On Thursday, October 19, 2017 at 12:42:44 PM UTC-4, john hanly wrote:

john hanly

unread,
Oct 19, 2017, 4:33:07 PM10/19/17
to VPython-users
They come from the import visual.controls import slider, controls, toggle.


On Thursday, October 19, 2017 at 12:42:44 PM UTC-4, john hanly wrote:

Aaron Titus

unread,
Oct 19, 2017, 5:35:40 PM10/19/17
to vpytho...@googlegroups.com
I’m sure the syntax has changed quite a bit for sliders, etc.

In my opinion, your best bet for running the code in the book is probably to install the old visual package (called classic in my instructions below). Here are the steps if you are using Anaconda:

1. Create an environment that uses Python 2.7 using the following command:

conda create -n classicvpython python=2.7 anaconda

2. Activate this environment using:

source activate classicvpython

3. Install the classic version of vpython using:

conda install -c mwcraig vpython

4. Now, assuming you’ve created a file named “test.py” that has sphere() in the file, you can test it using:

python test.py

And you should see a sphere.

If this works, then I suspect you can run the classic vpython code from the book.

Aaron

john hanly

unread,
Oct 19, 2017, 6:02:15 PM10/19/17
to VPython-users
thank you. that sounds like only option.


On Thursday, October 19, 2017 at 12:42:44 PM UTC-4, john hanly wrote:

John

unread,
Oct 20, 2017, 2:28:58 PM10/20/17
to VPython-users

There exists a conversion program to convert from Classic VPython to the new VPython 7. See details here.


http://www.glowscript.org/docs/VPythonDocs/index.html


where is says ...


"Many programs written in Classic VPython 6 will run in GlowScript VPython or VPython 7 without change after being run through a conversion program written in Python. This program converts (x,y,z) => vector(x,y,z) and obj.x => obj.pos.x. These changes are necessary because GlowScript does not recognize (x,y,z) as a vector nor obj.x as a shorthand for obj.pos.x. The program also converts display => canvas and gdisplay => graph. The program also converts scene.mouse.getclick() => scene.waitfor('click'), which works in both environments."


the python conversion program is.


http://www.glowscript.org/docs/GlowScriptDocs/VPtoGS.py


Try running your examples from the book through this conversion program.

Bruce Sherwood

unread,
Oct 20, 2017, 2:34:45 PM10/20/17
to VPython-users
But that conversion program doesn't handle widgets, which are VERY different between Classic and VPython 7.

Bruce
Reply all
Reply to author
Forward
0 new messages