ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 05 Apr 2022 18:55:32 +0200How do I install python modules, or use a different version of python? (with sage)https://ask.sagemath.org/question/8927/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?
Mon, 30 Apr 2012 23:21:41 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/Answer by ph4r05 for <p>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.</p>
<p>I want to run the following (combined with some output from sage)</p>
<pre><code>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()
</code></pre>
<p>It runs fine with the calls</p>
<pre><code>python drawT.sage
python2.7 drawT.sage
</code></pre>
<p>But when I try to call it directly or with a system call in sage I have problems.</p>
<pre><code>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
</code></pre>
<p>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:</p>
<pre><code>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
</code></pre>
<p>How can I install svgwrite, or invoke a given python installation from sage?</p>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?answer=42045#post-id-42045Or you can use embedded `pip`:
```
sage --pip install your-package
```
Mon, 16 Apr 2018 14:36:47 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?answer=42045#post-id-42045Comment by Max Alekseyev for <p>Or you can use embedded <code>pip</code>:</p>
<p><code>
sage --pip install your-package
</code></p>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=61835#post-id-61835I've accepted this answer since it's most up-to-date and works for modern versions of Sage.Tue, 05 Apr 2022 18:55:32 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=61835#post-id-61835Answer by John Palmieri for <p>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.</p>
<p>I want to run the following (combined with some output from sage)</p>
<pre><code>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()
</code></pre>
<p>It runs fine with the calls</p>
<pre><code>python drawT.sage
python2.7 drawT.sage
</code></pre>
<p>But when I try to call it directly or with a system call in sage I have problems.</p>
<pre><code>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
</code></pre>
<p>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:</p>
<pre><code>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
</code></pre>
<p>How can I install svgwrite, or invoke a given python installation from sage?</p>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?answer=13517#post-id-13517 1. [Download svgwrite](http://pypi.python.org/pypi/svgwrite/#downloads) 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.
Mon, 30 Apr 2012 23:35:52 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?answer=13517#post-id-13517Comment by John Palmieri for <ol>
<li><p><a href="http://pypi.python.org/pypi/svgwrite/#downloads">Download svgwrite</a> and unpack the gzipped tar file or the zip file.</p></li>
<li><p>From within the <code>svgwrite</code> directory, run <code>sage --python setup.py install</code>.</p></li>
<li><p>Then run <code>sage</code>: now <code>import svgwrite</code> should work.</p></li>
</ol>
<p>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.</p>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=17750#post-id-17750I wonder if easy_install would work, too: while running Sage, run `!easy_install svgwrite`. Wed, 08 May 2013 11:37:14 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=17750#post-id-17750Comment by John Palmieri for <ol>
<li><p><a href="http://pypi.python.org/pypi/svgwrite/#downloads">Download svgwrite</a> and unpack the gzipped tar file or the zip file.</p></li>
<li><p>From within the <code>svgwrite</code> directory, run <code>sage --python setup.py install</code>.</p></li>
<li><p>Then run <code>sage</code>: now <code>import svgwrite</code> should work.</p></li>
</ol>
<p>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.</p>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=17751#post-id-17751Do 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.Wed, 08 May 2013 11:35:32 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=17751#post-id-17751Comment by russ_hensel for <ol>
<li><p><a href="http://pypi.python.org/pypi/svgwrite/#downloads">Download svgwrite</a> and unpack the gzipped tar file or the zip file.</p></li>
<li><p>From within the <code>svgwrite</code> directory, run <code>sage --python setup.py install</code>.</p></li>
<li><p>Then run <code>sage</code>: now <code>import svgwrite</code> should work.</p></li>
</ol>
<p>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.</p>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=17758#post-id-17758other 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.Tue, 07 May 2013 19:43:18 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=17758#post-id-17758Answer by fccoelho for <p>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.</p>
<p>I want to run the following (combined with some output from sage)</p>
<pre><code>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()
</code></pre>
<p>It runs fine with the calls</p>
<pre><code>python drawT.sage
python2.7 drawT.sage
</code></pre>
<p>But when I try to call it directly or with a system call in sage I have problems.</p>
<pre><code>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
</code></pre>
<p>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:</p>
<pre><code>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
</code></pre>
<p>How can I install svgwrite, or invoke a given python installation from sage?</p>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?answer=15266#post-id-15266Another 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>Mon, 22 Jul 2013 12:39:59 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?answer=15266#post-id-15266Comment by bigduke for <p>Another possibility, if your package is hosted in the python package index (<a href="http://pypi.python.org">pypi.python.org</a>), is to run the following command:</p>
<pre><code>./sage --python -m easy_install <package_name>
</code></pre>
https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=23673#post-id-23673@fccoelho Thaanks a lot ! works fine for me using compiled code (.spyx).Sun, 03 Aug 2014 01:33:07 +0200https://ask.sagemath.org/question/8927/how-do-i-install-python-modules-or-use-a-different-version-of-python-with-sage/?comment=23673#post-id-23673