Ask Your Question
0

sage.graphs.graph import error

asked 2020-04-04 19:09:28 +0100

jctav gravatar image

Running sage on a file with only the following line:

from sage.graphs.graph import Graph

Results in the following ImportError

sage main.py Traceback (most recent call last):\

File "main.py", line 1, in <module>

from sage.graphs.graph import Graph

File "/usr/lib/python3.8/site-packages/sage/graphs/graph.py", line 416, in <module>

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

File "/usr/lib/python3.8/site-packages/sage/rings/polynomial/__init__.py", line 2, in <module>

import sage.rings.convert.mpfi

File "sage/rings/integer.pxd", line 7, in init sage.rings.convert.mpfi (build/cythonized/sage/rings/convert/mpfi.c:9642)

File "sage/rings/rational.pxd", line 8, in init sage.rings.integer (build/cythonized/sage/rings/integer.c:53129)

File "sage/rings/rational.pyx", line 95, in init sage.rings.rational (build/cythonized/sage/rings/rational.c:39892)

File "sage/rings/real_mpfr.pyx", line 1, in init sage.rings.real_mpfr (build/cythonized/sage/rings/real_mpfr.c:44245)

File "sage/rings/complex_number.pxd", line 6, in init sage.libs.mpmath.utils (build/cythonized/sage/libs/mpmath /utils.c:8639)

File "sage/rings/complex_double.pxd", line 7, in init sage.rings.complex_number (build/cythonized/sage/rings /complex_number.c:24023)

File "sage/rings/complex_double.pyx", line 96, in init sage.rings.complex_double (build/cythonized/sage/rings/complex_double.c:24202)

ImportError: cannot import name complex_number

Is this a bug? Or am I doing something wrong?

Thanks for the help in advance

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2020-04-04 19:18:19 +0100

vdelecroix gravatar image

Do

import sage.all
from sage.graphs.graph import Graph

The import.all does some important initialization steps.

edit flag offensive delete link more

Comments

Thank you so much. Is this commonly needed? Is it advisable to put this at the top of all scripts?

jctav gravatar imagejctav ( 2020-04-04 19:51:00 +0100 )edit

Unless your script is directly run inside a Sage environment, yes.

vdelecroix gravatar imagevdelecroix ( 2020-04-05 17:12:52 +0100 )edit

More precisely, if you rename the script as main.sage, the import statements are not necessary.

Sébastien gravatar imageSébastien ( 2020-04-06 12:57:30 +0100 )edit

Renaming main.py -> main.sage changes the behavior (ie the code is preparsed). My comment was preparser agnostic. If you do %runfile main.py in a Sage console, you don't need import sage.all because it was already done at the time you started Sage.

vdelecroix gravatar imagevdelecroix ( 2020-04-06 13:35:38 +0100 )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

1 follower

Stats

Asked: 2020-04-04 19:09:28 +0100

Seen: 1,143 times

Last updated: Apr 04 '20