Ask Your Question
1

run Python file from command line in Sage

asked 2013-05-31 09:25:44 +0200

updated 2013-05-31 09:31:56 +0200

I'm trying to run some Python file with Sage. I can import the module just fine within the interactive Sage IPython shell.

However, this very simple test fails:

sage sageruntest.py

where sageruntest.py contains the single line:

from sage.matrix.matrix2 import Matrix

It fails with:

Traceback (most recent call last):
  File "sageruntest.py", line 1, in <module>
    from sage.matrix.matrix2 import Matrix
  File "matrix2.pyx", line 1, in init sage.matrix.matrix2 (sage/matrix/matrix2.c:71259)
  File "matrix1.pyx", line 1, in init sage.matrix.matrix1 (sage/matrix/matrix1.c:13931)
  File "matrix0.pyx", line 32, in init sage.matrix.matrix0 (sage/matrix/matrix0.c:29567)
  File "/Applications/sage-5.9/local/lib/python2.7/site-packages/sage/modules/free_module.py", line 163, in <module>
    import free_module_element
  File "integer.pxd", line 9, in init sage.modules.free_module_element (sage/modules/free_module_element.c:30936)
  File "integer.pyx", line 178, in init sage.rings.integer (sage/rings/integer.c:38404)
  File "/Applications/sage-5.9/local/lib/python2.7/site-packages/sage/rings/infinity.py", line 203, in <module>
    import sage.rings.rational
  File "fast_arith.pxd", line 5, in init sage.rings.rational (sage/rings/rational.c:27749)
  File "fast_arith.pyx", line 51, in init sage.rings.fast_arith (sage/rings/fast_arith.c:8051)
  File "integer_ring.pyx", line 67, in init sage.rings.integer_ring (sage/rings/integer_ring.c:12156)
  File "/Applications/sage-5.9/local/lib/python2.7/site-packages/sage/structure/factorization.py", line 188, in <module>
    from sage.misc.all import prod
  File "/Applications/sage-5.9/local/lib/python2.7/site-packages/sage/misc/all.py", line 85, in <module>
    from functional import (additive_order,
  File "/Applications/sage-5.9/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 87, in init sage.rings.complex_double (sage/rings/complex_double.c:16745)
  File "real_mpfr.pxd", line 15, in init sage.rings.complex_number (sage/rings/complex_number.c:18304)
  File "real_mpfr.pyx", line 1, in init sage.rings.real_mpfr (sage/rings/real_mpfr.c:33344)
  File "utils.pyx", line 11, in init sage.libs.mpmath.utils (sage/libs/mpmath/utils.c:6633)
  File "/Applications/sage-5.9/local/lib/python2.7/site-packages/sage/all.py", line 86, in <module>
    from sage.libs.all       import *
  File "/Applications/sage-5.9/local/lib/python2.7/site-packages/sage/libs/all.py", line 1, in <module>
    import sage.libs.ntl.all  as ntl
  File "/Applications/sage-5.9/local/lib/python2.7/site-packages/sage/libs/ntl/__init__.py", line 1, in <module>
    import all
  File "/Applications/sage-5.9/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 24, in init sage.libs.ntl.ntl_ZZ (sage/libs/ntl/ntl_ZZ.cpp:7011)
ImportError: cannot import name IntegerRing

I just stumbled upon local/bin/sage-eval which imports this at the beginning:

import sys
from sage.all import *
from sage.calculus.predefined import x
from sage.misc.preparser import preparse

When I do ...

(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-05-31 11:56:50 +0200

Jesustc gravatar image

It is enough to add to sageruntest.py:

from sage.all import *
from sage.matrix.matrix2 import Matrix

Alternatively, the 2nd line (yours) is enough if you rename your file to sageruntest.sage (then it will be preparsed by Sage).

edit flag offensive delete link more

Comments

Instead of from sage.all import * you can just do import sage.all:

from sage.all import *
from sage.matrix.matrix2 import Matrix
slelievre gravatar imageslelievre ( 2017-12-12 05:02:21 +0200 )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

Stats

Asked: 2013-05-31 09:25:44 +0200

Seen: 3,138 times

Last updated: May 31 '13