Ask Your Question
2

How do I install python modules, or use a different version of python? (with sage)

asked 2012-04-30 16:21:41 -0600

alejandroerickson gravatar image

I have several versions of python, as well as the one included with sage. I want to use the svgwrite module in /Library/Frameworks/Python.framework/Versions/2.7/bin/python , but sage does not have it.

I want to run the following (combined with some output from sage)

import svgwrite

dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.line((0, 0), (10, 0), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.text('Test', insert=(0, 0.2), fill='red'))
dwg.save()

It runs fine with the calls

python drawT.sage
python2.7 drawT.sage

But when I try to call it directly or with a system call in sage I have problems.

sage: import sys
sage: os.system("python /path/drawT.sage")
Traceback (most recent call last):
  File "/path/drawT.sage", line 1, in <module>
    import svgwrite
ImportError: No module named svgwrite
256
sage: os.system("which python")
/Applications/sage/local/bin/python
0

Okay fine, sage's installation does not have the module. But now I try to force it to use the installation that does have it:

sage: os.system("which python2.7")
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
0
sage: os.system("python2.7 /path/drawT.sage")
Traceback (most recent call last):
  File "/path/drawT.sage", line 1, in <module>
    import svgwrite
ImportError: No module named svgwrite
256

How can I install svgwrite, or invoke a given python installation from sage?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
5

answered 2012-04-30 16:35:52 -0600

  1. Download svgwrite and unpack the gzipped tar file or the zip file.

  2. From within the svgwrite directory, run sage --python setup.py install.

  3. Then run sage: now import svgwrite should work.

That should install svgwrite in Sage's copy of Python. Using a different copy of Python with Sage is difficult, but installing Python packages in Sage's Python should be pretty straightforward.

edit flag offensive delete link more

Comments

other references show single - prior to python in any case my system responds python: can't open file 'setup.py': ........ So I am screwed I shoul note that I am using the sage appliance for the notebook.

russ_hensel gravatar imageruss_hensel ( 2013-05-07 12:43:18 -0600 )edit

Do you mean you are using Windows and the Sage virtual machine? I've never used that, but you could try following the instructions at http://wiki.sagemath.org/SageAppliance#Using_the_Sage_shell, and instead of item 6, cd to the svgwrite directory and running `sage --python setup.py install`. As far as using `-` or `--`, either should work.

John Palmieri gravatar imageJohn Palmieri ( 2013-05-08 04:35:32 -0600 )edit

I wonder if easy_install would work, too: while running Sage, run `!easy_install svgwrite`.

John Palmieri gravatar imageJohn Palmieri ( 2013-05-08 04:37:14 -0600 )edit
4

answered 2013-07-22 05:39:59 -0600

fccoelho gravatar image

Another possibility, if your package is hosted in the python package index (pypi.python.org), is to run the following command:

./sage --python -m easy_install <package_name>
edit flag offensive delete link more

Comments

@fccoelho Thaanks a lot ! works fine for me using compiled code (.spyx).

bigduke gravatar imagebigduke ( 2014-08-02 18:33:07 -0600 )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

1 follower

Stats

Asked: 2012-04-30 16:21:41 -0600

Seen: 7,437 times

Last updated: Jul 22 '13