Ask Your Question
1

Importing Sage functions into Cython gives me an error (but not on sagenb.org)

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

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/__init__.py", line 1, in <module>
    import all
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/plot/all.py", 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/plot.py", 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/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 "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/structure/factorization.py", line 188, in <module>
    from sage.misc.all import prod
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/misc/all.py", line 85, in <module>
    from functional import (additive_order,
  File "/usr/lib/sagemath/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 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/complex_field.py", line 110, in ComplexField
    C = ComplexField_class(prec)
  File "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/complex_field.py", 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/complex_field.py", 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 sagenb.org with the ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Stats

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

Seen: 593 times

Last updated: May 15 '13