This kind of problem has been around for a long time and it has been the case that the order in which imports get executed affects if circular import errors are raised. If the problem really was a circular import it shouldn't really matter in which order it happens: the cycle will always cause problems. So it seems it's just python being finicky -- or python having some special cases that allow it to handle some types of import cycles.
I don't know if this particular one already happened from the start but I do recall exactly this kind of thing being the issue. In this particular case, it seems executing import sage.rings.integer import sage.rings.integer_ring gets around the problem. It's of course why we have sage.all. In this case, sage.rings.all also works and would get you slightly less but probably still more than you want. The above example doesn't: sage.rings.integer is part of the cycle anyway. It may well be that in the past you imported ZZ with this little workaround of including an auxiliary import. On Wednesday, 24 September 2025 at 07:51:32 UTC-7 Michael Orlitzky wrote: > I went to type some sagelib code into ipython this morning, and got a > circular import error. The simplest reproducer is, > > $ python -q > >>> from sage.rings.integer_ring import ZZ > ... > ImportError: cannot import name 'ZZ' from partially initialized module > 'sage.rings.integer_ring' (most likely due to a circular import) > (/home/mjo/.../integer_ring.cpython-313-riscv64-linux-musl.so) > > This particular instance is from the loop, > > integer_ring -> integer > -> rational > -> rational_field > -> categories/finite_fields > -> integer_ring > > which is easily fixable. Yet after fixing it, I still get an > AttributeError from the integer <-> integer_ring loop: > > $ python -q > >>> from sage.rings.integer_ring import ZZ > Traceback (most recent call last): > File "<python-input-0>", line 1, in <module> > from sage.rings.integer_ring import ZZ > File "sage/rings/integer_ring.pyx", line 1, in init sage.rings.integer_ring > r""" > File "sage/rings/integer.pyx", line 312, in init sage.rings.integer > cdef Parent the_integer_ring = integer_ring.ZZ > AttributeError: partially initialized module > 'sage.rings.integer_ring' from > '/home/mjo/.../integer_ring.cpython-313-riscv64-linux-musl.so' > has no attribute 'ZZ' (most likely due to a circular import) > > This has me confused. I'm certain I've imported ZZ from python before, > and I'm also pretty sure that the integer <-> integer_ring loop is not > new. > > Has anything else changed? Is it just me? (This requires sagelib to be > installed as a python package via pip, meson, or a package manager; it > works fine from within a sage prompt.) > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sage-devel/af0be3a6-0869-4ca5-96e9-71ea25e30c85n%40googlegroups.com.
