Ask Your Question
1

Does or will Sage support the Visual Python module?

asked 2012-01-08 10:03:14 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Does or will Sage support the Visual Python (http://vpython.org/) module?

I use it to create 3D examples for several of my courses including Calculus III, Differential Equations, Modern Algebra, Combinatorics and my students use it for projects in both Modern Algebra and Scientific Computation.

Adam Hausknecht, Department of Mathematics, UMass Dartmouth

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2012-01-08 11:07:32 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

You can use any python module in sage. I just tried a simple example in sage, but it opens in a new window and not in the browser itself. You have to however import the module from the outside, as visual is not part of sage yet. Just try the following to see whether you can get visual python working with sage. It works for me.

import sys
sys.path.append('/usr/lib/python2.7/dist-packages')
from visual import *
sphere()

Note, that depending on the version of python you are using the path to the visual module may differ on your machine.

edit flag offensive delete link more

Comments

Note that Sage has its own Python. Hence, rather than using "visual" from the global Python version on your machine (which may be a different version than Sage's Python!), I think it would be better to install the visual module into Sage's Python

Simon King gravatar imageSimon King ( 2012-01-08 20:50:18 -0500 )edit

Too bad, I thought I can have line breaks in a comment. Anyway: In order to install any new Python module in Sage, just open a Sage shell (i.e., if "sage" is the command for launching an interactive Sage session, do "sage -sh"). In that shell, the commands "singular", "gap", "python" and so on will refer to Sage's own versions of Singular, GAP and python. Hence, in the Sage shell, you'd just do whatever needed to install the package, and then it will automatically be in the right version of Python.

Simon King gravatar imageSimon King ( 2012-01-08 20:53:46 -0500 )edit

Alternatively, I like to do things the other way round. Write a Python (2.x) package and use "from sage import *" to use sage functions. Then it should work with everything.

tririver gravatar imagetririver ( 2012-01-09 00:56:29 -0500 )edit
1

answered 2012-01-09 07:37:52 -0500

Simon King gravatar image

As I said in a comment above: It is not recommended to install some package in one python installation (e.g., some system-wide installation) and then import it into a totally different installation (e.g., the Sage installation).

It is important to keep in mind that Sage includes "batteries": It includes Python, it includes GAP, it includes Maxima, Singular, you name it. Hence, when you want to use a specific Python package in Sage then you should install it in Sage's Python, and nowhere else.

Hence, open a Sage shell (if sage is in your path then do "sage -sh"), and then do whatever is needed to install the package. Namely, in the Sage shell, "python" and "gap" and "singular" will automatically be Sage's versions, not the system-wide versions.

edit flag offensive delete link more
0

answered 2012-01-09 06:26:52 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi all,

Thanks for your responses! Om my MacBook Pro Intel Core I7, I had to change the suggested lines of code to:

import sys sys.path.append('/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages')

import visual

However, when this is evaluated by Sage, I get the error message:


Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_19.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("aW1wb3J0IHN5cwpzeXMucGF0aC5hcHBlbmQoJy9MaWJyYXJ5L0ZyYW1ld29ya3MvUHl0aG9uLmZyYW1ld29yay9WZXJzaW9ucy8yLjcvbGliL3B5dGhvbjIuNy9zaXRlLXBhY2thZ2VzJykKaW1wb3J0IHZpc3VhbA=="),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

File "/private/var/folders/45/450VCFXnGmmTeo+fv0sWMk+++TI/-Tmp-/tmp3XxlCy/___code___.py", line 4, in <module> exec compile(u'import visual File "", line 1, in <module>

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/visual/__init__.py", line 1, in <module> from .visual_all import * File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/visual/visual_all.py", line 1, in <module> from vis import version File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vis/__init__.py", line 3, in <module> from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate, ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vis/cvisual.so, 2): no suitable image found. Did find:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vis/cvisual.so: mach-o, but wrong architecture

I take this to mean that the visual python package has been compiled for an architecture that is incompatible with Sage.

Note: I used the Mac OS installer at

                 http://vpython.org/contents/download_mac.html

to install Visual Python as a Mac OS Framework; consequently, vPython is not installed in the same manner as most Python packages!

Regards,

Adam Hausknecht

edit flag offensive delete link more

Comments

I have same symptom ". . .vis/cvisual.so: mach-o, but wrong architecture)\" when I attempt to run VIDLE. Unfortunately, I have not been able to figure out how to fix it.

Xander Nerdski gravatar imageXander Nerdski ( 2013-07-27 04:24:38 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-01-08 10:03:14 -0500

Seen: 470 times

Last updated: Jan 09 '12