ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 24 May 2019 22:40:36 -0500What packages in sage can I use in python?http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/As I know, there is not a good tutorial explainging how to import sage packages in python. When I `list_packages` of sage, it shows that `numpy, scipy, python_igraph` are installed. Then I want to import these packages in python with the following codes
```
from sage.all import *
```
I can use `numpy, scipy` while `python_igraph` does not work. Could anyone explain why `numpy, scipy` work while `python_igraph` does not? How to get `python_igraph` work?
And what packages in sage can I use in python? Is there any explicit tutorial?Mon, 07 Nov 2016 05:08:01 -0600http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/Answer by vstuart for <p>As I know, there is not a good tutorial explainging how to import sage packages in python. When I <code>list_packages</code> of sage, it shows that <code>numpy, scipy, python_igraph</code> are installed. Then I want to import these packages in python with the following codes</p>
<p><code>
from sage.all import *
</code></p>
<p>I can use <code>numpy, scipy</code> while <code>python_igraph</code> does not work. Could anyone explain why <code>numpy, scipy</code> work while <code>python_igraph</code> does not? How to get <code>python_igraph</code> work?</p>
<p>And what packages in sage can I use in python? Is there any explicit tutorial?</p>
http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?answer=46659#post-id-46659Re: igraph import error. I installed sage (sagemath) on Arch Linux,
[victoria@victoria ~]$ pacman -Ss sagemath | grep -i installed
community/sage-data-elliptic_curves 0.8.1-1 [installed]
community/sagemath 8.7-4 [installed]
[victoria@victoria ~]$ which sage
/usr/bin/sage
In my Python 3.7 venv:
(/home/victoria/venv/py37) [victoria@victoria ~]$ sage
┌────────────────────────────────────────────────┐
│ SageMath version 8.7, Release Date: 2019-03-23 │
│ Using Python 2.7.16. Type "help()" for help. │
└────────────────────────────────────────────────┘
## NOTE: even in py37 venv, using sage's py27
sage: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-73ffca960e68> in <module>()
----> 1 import igraph
ImportError: No module named igraph
sage:
Exiting Sage (CPU time 0m0.11s, Wall time 1m13.47s).
# ----------------------------------------
## Need system (Arch Linux) install of: python2-igraph
[victoria@victoria ~]$ pacman -Ss igraph | grepic python
A program for computing automorphism groups of graphs and digraphs
community/python-igraph 0.7.1.post6-5 [installed]
Python bindings for the igraph library
community/python2-igraph 0.7.1.post6-5
Python 2 bindings for the igraph library
[victoria@victoria ~]$ sudo pacman -S python2-igraph
...
(1/1) installing python2-igraph [#################################] 100%
# ----------------------------------------
[victoria@victoria ~]$ sage
┌────────────────────────────────────────────────┐
│ SageMath version 8.7, Release Date: 2019-03-23 │
│ Using Python 2.7.16. Type "help()" for help. │
└────────────────────────────────────────────────┘
sage: from sage import *
sage: import igraph
sage:
Fri, 24 May 2019 22:40:36 -0500http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?answer=46659#post-id-46659Answer by slelievre for <p>As I know, there is not a good tutorial explainging how to import sage packages in python. When I <code>list_packages</code> of sage, it shows that <code>numpy, scipy, python_igraph</code> are installed. Then I want to import these packages in python with the following codes</p>
<p><code>
from sage.all import *
</code></p>
<p>I can use <code>numpy, scipy</code> while <code>python_igraph</code> does not work. Could anyone explain why <code>numpy, scipy</code> work while <code>python_igraph</code> does not? How to get <code>python_igraph</code> work?</p>
<p>And what packages in sage can I use in python? Is there any explicit tutorial?</p>
http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?answer=35470#post-id-35470Note that Sage ships its own Python, which is distinct from your system-wide Python.
The packages installed for Sage's Python have no influence on your system-wide Python.
The packages installed for your system-wide Python have no influence on Sage's Python.
To start Sage's Python, run `sage -python` or `sage -ipython` in a terminal.
Sage's Python comes equipped with many packages (numpy, scipy, sympy, etc).
Some of them are imported by Sage at startup, some are not. For instance,
even though they are standard packages, numpy and scipy are not imported
by Sage at startup. To use them in Sage, you need an explicit `import`.
Optional packages (such as igraph) need to be installed first.
After you have installed some new packages for Sage, restart Sage's Python
and you can import them.
In the case of `igraph` and `python_igraph`, it seems that you need
to install both, but to use them you only need to type `import igraph`.
Before:
$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import scipy
In [3]: import sage
In [4]: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-8e950eb5d8d8> in <module>()
----> 1 import igraph
ImportError: No module named igraph
Installing:
$ sage -i igraph
...
[igraph-0.7.1] Finished installing igraph-0.7.1.spkg
real 3m23.309s
user 7m38.410s
sys 1m6.209s
Sage build/upgrade complete!
$ sage -i python_igraph
...
Sage build/upgrade complete!
$
After:
$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import igraph
In [2]:Mon, 07 Nov 2016 07:20:37 -0600http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?answer=35470#post-id-35470Comment by edenharder for <p>Note that Sage ships its own Python, which is distinct from your system-wide Python.
The packages installed for Sage's Python have no influence on your system-wide Python.
The packages installed for your system-wide Python have no influence on Sage's Python.</p>
<p>To start Sage's Python, run <code>sage -python</code> or <code>sage -ipython</code> in a terminal.</p>
<p>Sage's Python comes equipped with many packages (numpy, scipy, sympy, etc).</p>
<p>Some of them are imported by Sage at startup, some are not. For instance,
even though they are standard packages, numpy and scipy are not imported
by Sage at startup. To use them in Sage, you need an explicit <code>import</code>.</p>
<p>Optional packages (such as igraph) need to be installed first.
After you have installed some new packages for Sage, restart Sage's Python
and you can import them.</p>
<p>In the case of <code>igraph</code> and <code>python_igraph</code>, it seems that you need
to install both, but to use them you only need to type <code>import igraph</code>.</p>
<p>Before:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import scipy
In [3]: import sage
In [4]: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-8e950eb5d8d8> in <module>()
----> 1 import igraph
ImportError: No module named igraph
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -i igraph
...
[igraph-0.7.1] Finished installing igraph-0.7.1.spkg
real 3m23.309s
user 7m38.410s
sys 1m6.209s
Sage build/upgrade complete!
$ sage -i python_igraph
...
Sage build/upgrade complete!
$
</code></pre>
<p>After:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import igraph
In [2]:
</code></pre>
http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35484#post-id-35484done! https://ask.sagemath.org/question/35483/what-does-from-sageall-import-do/Tue, 08 Nov 2016 12:39:16 -0600http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35484#post-id-35484Comment by slelievre for <p>Note that Sage ships its own Python, which is distinct from your system-wide Python.
The packages installed for Sage's Python have no influence on your system-wide Python.
The packages installed for your system-wide Python have no influence on Sage's Python.</p>
<p>To start Sage's Python, run <code>sage -python</code> or <code>sage -ipython</code> in a terminal.</p>
<p>Sage's Python comes equipped with many packages (numpy, scipy, sympy, etc).</p>
<p>Some of them are imported by Sage at startup, some are not. For instance,
even though they are standard packages, numpy and scipy are not imported
by Sage at startup. To use them in Sage, you need an explicit <code>import</code>.</p>
<p>Optional packages (such as igraph) need to be installed first.
After you have installed some new packages for Sage, restart Sage's Python
and you can import them.</p>
<p>In the case of <code>igraph</code> and <code>python_igraph</code>, it seems that you need
to install both, but to use them you only need to type <code>import igraph</code>.</p>
<p>Before:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import scipy
In [3]: import sage
In [4]: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-8e950eb5d8d8> in <module>()
----> 1 import igraph
ImportError: No module named igraph
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -i igraph
...
[igraph-0.7.1] Finished installing igraph-0.7.1.spkg
real 3m23.309s
user 7m38.410s
sys 1m6.209s
Sage build/upgrade complete!
$ sage -i python_igraph
...
Sage build/upgrade complete!
$
</code></pre>
<p>After:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import igraph
In [2]:
</code></pre>
http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35481#post-id-35481I suggest you open a new ask-sage question asking "What does `from sage.all import *` do?".
In the text of the question, you might refer to the question you asked here (ask sage question 35464).
Don't check the "community wiki" checkbox: it prevents you from earning karma points from your questions.Tue, 08 Nov 2016 09:14:03 -0600http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35481#post-id-35481Comment by edenharder for <p>Note that Sage ships its own Python, which is distinct from your system-wide Python.
The packages installed for Sage's Python have no influence on your system-wide Python.
The packages installed for your system-wide Python have no influence on Sage's Python.</p>
<p>To start Sage's Python, run <code>sage -python</code> or <code>sage -ipython</code> in a terminal.</p>
<p>Sage's Python comes equipped with many packages (numpy, scipy, sympy, etc).</p>
<p>Some of them are imported by Sage at startup, some are not. For instance,
even though they are standard packages, numpy and scipy are not imported
by Sage at startup. To use them in Sage, you need an explicit <code>import</code>.</p>
<p>Optional packages (such as igraph) need to be installed first.
After you have installed some new packages for Sage, restart Sage's Python
and you can import them.</p>
<p>In the case of <code>igraph</code> and <code>python_igraph</code>, it seems that you need
to install both, but to use them you only need to type <code>import igraph</code>.</p>
<p>Before:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import scipy
In [3]: import sage
In [4]: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-8e950eb5d8d8> in <module>()
----> 1 import igraph
ImportError: No module named igraph
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -i igraph
...
[igraph-0.7.1] Finished installing igraph-0.7.1.spkg
real 3m23.309s
user 7m38.410s
sys 1m6.209s
Sage build/upgrade complete!
$ sage -i python_igraph
...
Sage build/upgrade complete!
$
</code></pre>
<p>After:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import igraph
In [2]:
</code></pre>
http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35476#post-id-35476Thanks! [How do I import Sage into a Python script](http://doc.sagemath.org/html/en/faq/faq-usage.html#how-do-i-import-sage-into-a-python-script) told me that to use `from sage.all import *` to import sage packages. When I list the installed sage packages, there is igraph and python-igraph. But `from sage.all import *` will not import them into python. I'd like to know, what kind of packages can be imported when I use `from sage.all import *`.Tue, 08 Nov 2016 05:51:06 -0600http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35476#post-id-35476Comment by slelievre for <p>Note that Sage ships its own Python, which is distinct from your system-wide Python.
The packages installed for Sage's Python have no influence on your system-wide Python.
The packages installed for your system-wide Python have no influence on Sage's Python.</p>
<p>To start Sage's Python, run <code>sage -python</code> or <code>sage -ipython</code> in a terminal.</p>
<p>Sage's Python comes equipped with many packages (numpy, scipy, sympy, etc).</p>
<p>Some of them are imported by Sage at startup, some are not. For instance,
even though they are standard packages, numpy and scipy are not imported
by Sage at startup. To use them in Sage, you need an explicit <code>import</code>.</p>
<p>Optional packages (such as igraph) need to be installed first.
After you have installed some new packages for Sage, restart Sage's Python
and you can import them.</p>
<p>In the case of <code>igraph</code> and <code>python_igraph</code>, it seems that you need
to install both, but to use them you only need to type <code>import igraph</code>.</p>
<p>Before:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import scipy
In [3]: import sage
In [4]: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-8e950eb5d8d8> in <module>()
----> 1 import igraph
ImportError: No module named igraph
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -i igraph
...
[igraph-0.7.1] Finished installing igraph-0.7.1.spkg
real 3m23.309s
user 7m38.410s
sys 1m6.209s
Sage build/upgrade complete!
$ sage -i python_igraph
...
Sage build/upgrade complete!
$
</code></pre>
<p>After:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import igraph
In [2]:
</code></pre>
http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35473#post-id-35473Please suggest any improvement to the tutorial. Could you specify which part of the tutorial should be improved?Tue, 08 Nov 2016 03:03:55 -0600http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35473#post-id-35473Comment by edenharder for <p>Note that Sage ships its own Python, which is distinct from your system-wide Python.
The packages installed for Sage's Python have no influence on your system-wide Python.
The packages installed for your system-wide Python have no influence on Sage's Python.</p>
<p>To start Sage's Python, run <code>sage -python</code> or <code>sage -ipython</code> in a terminal.</p>
<p>Sage's Python comes equipped with many packages (numpy, scipy, sympy, etc).</p>
<p>Some of them are imported by Sage at startup, some are not. For instance,
even though they are standard packages, numpy and scipy are not imported
by Sage at startup. To use them in Sage, you need an explicit <code>import</code>.</p>
<p>Optional packages (such as igraph) need to be installed first.
After you have installed some new packages for Sage, restart Sage's Python
and you can import them.</p>
<p>In the case of <code>igraph</code> and <code>python_igraph</code>, it seems that you need
to install both, but to use them you only need to type <code>import igraph</code>.</p>
<p>Before:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import scipy
In [3]: import sage
In [4]: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-8e950eb5d8d8> in <module>()
----> 1 import igraph
ImportError: No module named igraph
</code></pre>
<p>Installing:</p>
<pre><code>$ sage -i igraph
...
[igraph-0.7.1] Finished installing igraph-0.7.1.spkg
real 3m23.309s
user 7m38.410s
sys 1m6.209s
Sage build/upgrade complete!
$ sage -i python_igraph
...
Sage build/upgrade complete!
$
</code></pre>
<p>After:</p>
<pre><code>$ sage -ipython
Python 2.7.10 (default, Oct 26 2016, 00:37:24)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import igraph
In [2]:
</code></pre>
http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35471#post-id-35471Thanks for your reply! I tested after I installed `python-igraph` and `igraph`, they were still cannot be imported by python. Then I `sage -f python2` and now I can import `igraph` in python. And I wonder that why the only tutorial teaches `from sage.all import *` but not directly `import somepackage`?Mon, 07 Nov 2016 07:38:10 -0600http://ask.sagemath.org/question/35464/what-packages-in-sage-can-i-use-in-python/?comment=35471#post-id-35471