Ask Your Question

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

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

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'))

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
sage: os.system("which python")

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")
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

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

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

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

  2. From within the svgwrite directory, run sage --python 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


other references show single - prior to python in any case my system responds python: can't open file '': ........ 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 -0500 )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, and instead of item 6, cd to the svgwrite directory and running `sage --python install`. As far as using `-` or `--`, either should work.

John Palmieri gravatar imageJohn Palmieri ( 2013-05-08 04:35:32 -0500 )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 -0500 )edit

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

fccoelho gravatar image

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

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


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

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

1 follower


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

Seen: 7,068 times

Last updated: Jul 22 '13