Ask Your Question

Importing Sage functions into Cython gives me an error (but not on

asked 2013-05-15 12:03:41 +0200

Alan Chang gravatar image

If I make a file (call it a.spyx) consisting of one line:

from sage.plot.plot import list_plot

and run it in the terminal with the command sage a.spyx, I get the following error

$ sage a.spyx
Compiling a.spyx...
Traceback (most recent call last):
  File "/usr/lib/sagemath/local/bin/sage-run-cython", line 9, in <module>
    eval(compile(s, tmp_filename(), 'exec'))
  File "/home/alan/.sage/temp/alan_MacBookPro/12384/tmp_sIOI1_", line 1, in <module>

  File "_home_alan_Desktop_zeta_zero_rmt_a_spyx_0.pyx", line 7, in init _home_alan_Desktop_zeta_zero_rmt_a_spyx_0 (_home_alan_Desktop_zeta_zero_rmt_a_spyx_0.c:1400)
    from sage.plot.plot import list_plot
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/plot/", line 1, in <module>
    import all
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/plot/", line 2, in <module>
    from plot import plot, graphics_array, list_plot, parametric_plot, polar_plot
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/plot/", line 367, in <module>
    from sage.ext.fast_eval import fast_float, fast_float_constant, is_fast_float
  File "fast_eval.pyx", line 90, in init sage.ext.fast_eval (sage/ext/fast_eval.c:10738)
  File "real_mpfr.pxd", line 15, in init sage.ext.fast_callable (sage/ext/fast_callable.c:16772)
  File "integer.pxd", line 9, in init sage.rings.real_mpfr (sage/rings/real_mpfr.c:33329)
  File "integer.pyx", line 178, in init sage.rings.integer (sage/rings/integer.c:38404)
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/", 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 "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/structure/", line 188, in <module>
    from sage.misc.all import prod
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/misc/", line 85, in <module>
    from functional import (additive_order,
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/misc/", line 36, in <module>
    from sage.rings.complex_double import CDF
  File "complex_double.pyx", line 91, in init sage.rings.complex_double (sage/rings/complex_double.c:16774)
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/", line 110, in ComplexField
    C = ComplexField_class(prec)
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/", line 202, in __init__
    ParentWithGens.__init__(self, self._real_field(), ('I',), False, category = Fields())
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/", line 293, in _real_field
    self.__real_field = real_mpfr.RealField(self._prec)
  File "real_mpfr.pyx", line 363, in sage.rings.real_mpfr.RealField (sage/rings/real_mpfr.c:4952)
  File "real_mpfr.pyx", line 415, in sage.rings.real_mpfr.RealField (sage/rings/real_mpfr.c:4711)
TypeError: 'NoneType' object has no attribute '__getitem__'

(The same error occurs if I try to import any other Sage function.)

However, if I create a new worksheet on with the ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-05-15 13:43:49 +0200

vdelecroix gravatar image

A .spyx file is not intended to be run with "sage my_file.pyx". You should rather do inside a Sage console

sage: %runfile my_file.spyx

to run once the file, or

sage: %attach my_file.spyx

if you would like that the file is recompiled and reimported each time it has changed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-05-15 12:03:41 +0200

Seen: 556 times

Last updated: May 15 '13