Ask Your Question
3

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

asked 2012-04-30 23:21:41 +0100

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

3 Answers

Sort by ยป oldest newest most voted
1

answered 2018-04-16 14:36:47 +0100

ph4r05 gravatar image

Or you can use embedded pip:

sage --pip install your-package

edit flag offensive delete link more

Comments

I've accepted this answer since it's most up-to-date and works for modern versions of Sage.

Max Alekseyev gravatar imageMax Alekseyev ( 2022-04-05 18:55:32 +0100 )edit
5

answered 2012-04-30 23:35:52 +0100

  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 19:43:18 +0100 )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 11:35:32 +0100 )edit

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

John Palmieri gravatar imageJohn Palmieri ( 2013-05-08 11:37:14 +0100 )edit
4

answered 2013-07-22 12:39:59 +0100

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-03 01:33:07 +0100 )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 23:21:41 +0100

Seen: 15,616 times

Last updated: Jul 22 '13