Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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?