sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.39k stars 473 forks source link

Importing a specific module usually fails #13083

Open ec1e6b34-7d5f-489e-a90e-cd5ca2de718c opened 12 years ago

ec1e6b34-7d5f-489e-a90e-cd5ca2de718c commented 12 years ago

When I run sage --python and then try to import something "specific" (e.g. from the rings module), I get the following:

$ sage --python
Python 2.7.2 (default, May 16 2012, 20:18:27) 
[GCC 4.6.3] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sage.rings.all import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/rings/all.py", line 42, in <module>
    from ideal import Ideal, is_Ideal
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/rings/ideal.py", line 35, in <module>
    from sage.interfaces.singular import singular as singular_default
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/interfaces/singular.py", line 340, in <module>
    import sage.rings.integer
  File "integer.pyx", line 170, in init sage.rings.integer (sage/rings/integer.c:35815)
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/rings/infinity.py", line 200, in <module>
    import sage.rings.rational
  File "fast_arith.pxd", line 5, in init sage.rings.rational (sage/rings/rational.c:25959)
  File "fast_arith.pyx", line 51, in init sage.rings.fast_arith (sage/rings/fast_arith.c:7723)
  File "integer_ring.pyx", line 69, in init sage.rings.integer_ring (sage/rings/integer_ring.c:11304)
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/structure/factorization.py", line 188, in <module>
    from sage.misc.all import prod
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/misc/all.py", line 81, in <module>
    from functional import (additive_order,
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/misc/functional.py", line 36, in <module>
    from sage.rings.complex_double import CDF
  File "complex_double.pyx", line 88, in init sage.rings.complex_double (sage/rings/complex_double.c:15160)
  File "real_mpfr.pxd", line 15, in init sage.rings.complex_number (sage/rings/complex_number.c:16587)
  File "real_mpfr.pyx", line 1, in init sage.rings.real_mpfr (sage/rings/real_mpfr.c:30314)
  File "utils.pyx", line 11, in init sage.libs.mpmath.utils (sage/libs/mpmath/utils.c:6099)
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/all.py", line 72, in <module>
    from sage.libs.all       import *
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/libs/all.py", line 1, in <module>
    import sage.libs.ntl.all  as ntl
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/libs/ntl/__init__.py", line 1, in <module>
    import all
  File "/Applications/sage/local/lib/python2.7/site-packages/sage/libs/ntl/all.py", line 26, in <module>
    from sage.libs.ntl.ntl_ZZ import (
  File "ntl_ZZ.pyx", line 28, in init sage.libs.ntl.ntl_ZZ (sage/libs/ntl/ntl_ZZ.cpp:6393)
  File "integer_ring.pyx", line 1062, in sage.rings.integer_ring.IntegerRing (sage/rings/integer_ring.c:9840)
NameError: ZZ

This also happens for other modules, e.g. from sage.modules.all import *. However, it does not occur when I do

from sage.all import *

first.

Component: misc

Issue created by migration from https://trac.sagemath.org/ticket/13083

mwhansen commented 12 years ago
comment:1

Before you can do any of those specific imports, you need to do

import sage.all

which will import things in the correct order and make sure everything is initialized. After that, you can import what you need.

hivert commented 12 years ago
comment:2

Replying to @mwhansen:

Before you can do any of those specific imports, you need to do

import sage.all

which will import things in the correct order and make sure everything is initialized. After that, you can import what you need.

I think this nevertheless witnesses some problems with Sage's imports and modularity. Is there a good reason why this shouldn't work ?

Florent

jdemeyer commented 9 years ago

Description changed:

--- 
+++ 
@@ -1,7 +1,7 @@
-When I run `sage -python` and then try to import something "specific" (e.g. from the `rings` module), I get the following:
+When I run `sage --python` and then try to import something "specific" (e.g. from the `rings` module), I get the following:

-$ sage -python +$ sage --python Python 2.7.2 (default, May 16 2012, 20:18:27) [GCC 4.6.3] on darwin Type "help", "copyright", "credits" or "license" for more information. @@ -49,18 +49,4 @@ from sage.all import *


-first. Likewise, the import works in ordinary `sage`:
-
-```
-$ sage
-----------------------------------------------------------------------
-| Sage Version 5.0, Release Date: 2012-05-14                         |
-| Type notebook() for the GUI, and license() for information.        |
-----------------------------------------------------------------------
-sage: from sage.rings.integer_ring import *
-sage:
-```
-
-Issuing `sage -sh` before `sage -python` does not help though.
-
-I'm running Sage 5.0 on Mac OS X 10.5.8.
+first.