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.Mon, 11 Dec 2017 21:38:30 -0600- Error when trying to import without sage.allhttp://ask.sagemath.org/question/40116/error-when-trying-to-import-without-sageall/I am trying to import only the Sage functions needed as is done in the Sage source code, but I am running into issues. For example, (running `sage -python`),
>>> from sage.groups.group import Group
results in
...
from sage.rings.complex_double import CDF
File "sage/rings/real_double.pxd", line 8, in init sage.rings.complex_double (/export/pkgs/linux-rh6/sagemath-7.0/src/build/cythonized/sage/rings/complex_double.c:22654)
File "sage/rings/real_double.pyx", line 64, in init sage.rings.real_double (/export/pkgs/linux-rh6/sagemath-7.0/src/build/cythonized/sage/rings/real_double.c:25060)
ImportError: cannot import name ZZ
(I can post the full traceback if that would be helpful.) Similar things happen for almost any import I try. I was using the `import_statements` to determine what to import.
Am I missing something?
EDIT:
I think I get the picture a little better now. The Sage source files aren't meant to be imported in Python, they are meant to be imported into Sage, which presumably runs `import sage.all` when it starts.Mon, 11 Dec 2017 21:06:39 -0600http://ask.sagemath.org/question/40116/error-when-trying-to-import-without-sageall/
- Answer by slelievre for <p>I am trying to import only the Sage functions needed as is done in the Sage source code, but I am running into issues. For example, (running <code>sage -python</code>),</p>
<pre><code>>>> from sage.groups.group import Group
</code></pre>
<p>results in</p>
<pre><code>...
from sage.rings.complex_double import CDF
File "sage/rings/real_double.pxd", line 8, in init sage.rings.complex_double (/export/pkgs/linux-rh6/sagemath-7.0/src/build/cythonized/sage/rings/complex_double.c:22654)
File "sage/rings/real_double.pyx", line 64, in init sage.rings.real_double (/export/pkgs/linux-rh6/sagemath-7.0/src/build/cythonized/sage/rings/real_double.c:25060)
ImportError: cannot import name ZZ
</code></pre>
<p>(I can post the full traceback if that would be helpful.) Similar things happen for almost any import I try. I was using the <code>import_statements</code> to determine what to import.</p>
<p>Am I missing something?</p>
<p>EDIT:</p>
<p>I think I get the picture a little better now. The Sage source files aren't meant to be imported in Python, they are meant to be imported into Sage, which presumably runs <code>import sage.all</code> when it starts.</p>
http://ask.sagemath.org/question/40116/error-when-trying-to-import-without-sageall/?answer=40117#post-id-40117You first need to `import sage.all`.
The following should work (I'm including version info for reference):
$ sage -v
SageMath version 8.1, Release Date: 2017-12-07
$ sage -python
Python 2.7.14 (default, Dec 9 2017, 17:25:34)
[GCC 7.2.0] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sage.all
>>> from sage.groups.group import Group
>>>
References:
- [2015-01-28 post by Jeroen Demeyer on sage-support](https://groups.google.com/d/msg/sage-support/3lXInDgHJe4/SdOpuuOkqPUJ)
- [2015-02-10 post by Nicolas M. ThiĆ©ry on sage-combinat-devel](https://groups.google.com/d/msg/sage-combinat-devel/oi4VtGr1g5A/B8PE7ra8krAJ)Mon, 11 Dec 2017 21:38:30 -0600http://ask.sagemath.org/question/40116/error-when-trying-to-import-without-sageall/?answer=40117#post-id-40117