First time here? Check out the FAQ!

Ask Your Question
0

sage.graphs.graph import error

asked 5 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 5 years ago

vdelecroix gravatar image

Do

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

The import.all does some important initialization steps.

Preview: (hide)
link

Comments

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

jctav gravatar imagejctav ( 5 years ago )

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

vdelecroix gravatar imagevdelecroix ( 5 years ago )

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

Sébastien gravatar imageSébastien ( 5 years ago )

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 ( 5 years ago )

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: 5 years ago

Seen: 1,297 times

Last updated: Apr 04 '20