Ask Your Question
0

import tetrahedron error

asked 2025-09-09 10:00:50 +0200

ortollj gravatar image

updated 2025-09-09 10:18:44 +0200

Hi

Sagemath10.4, Ubuntu24.04, WSL, Edge with Copilot, W11

AI Copilot said me :

that’s a classic SageMath quirk. The error:

from sage.plot.plot3d.shapes2 import tetrahedron

ImportError: cannot import name 'tetrahedron' from 'sage.plot.plot3d.shapes2'

means Sage doesn’t actually provide a tetrahedron function in that module, even though it seems like it should. That import line is misleading — and I’m guilty of trusting it too quickly.

#import sage.plot.plot3d.shapes2
#tetrahedron?
from sage.plot.plot3d.shapes2 import tetrahedron

is her,he,it right ?

edit retag flag offensive close merge delete

Comments

I forgot to precise :jupyter-notebook : 5.2.2

ortollj gravatar imageortollj ( 2025-09-09 13:18:44 +0200 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2025-09-25 15:59:58 +0200

eric_g gravatar image

An alternative is to use Sage's function import_statements:

sage: import_statements("tetrahedron")
from sage.plot.plot3d.platonic import tetrahedron
edit flag offensive delete link more
1

answered 2025-09-09 10:44:03 +0200

rburing gravatar image

updated 2025-09-09 10:47:03 +0200

Use the source: https://github.com/search?q=repo%3Asa...

Or within a SageMath session:

sage: search_src('def tetrahedron')
plot/plot3d/platonic.py:156:def tetrahedron(center=(0, 0, 0), size=1, **kwds):
geometry/polyhedron/library.py:1118:    def tetrahedron(self, backend=None):

The function is found in the file src/sage/plot/plot3d/platonic.py, so the correct import statement is:

from sage.plot.plot3d.platonic import tetrahedron
edit flag offensive delete link more

Comments

but why if I write:

import sage.plot.plot3d.shapes2
tetrahedron?

then I access to tetrahedron ?

ortollj gravatar imageortollj ( 2025-09-09 10:59:49 +0200 )edit

Ok, Copilot told me :

🧠 Sage’s Lazy Import System Sage uses a preloaded global namespace in its interactive environment (especially in Jupyter notebooks and the Sage REPL). This means: Many commonly used functions — like tetrahedron, sphere, Polyhedron, etc. — are automatically available without explicit import. Even if you don’t do from sage.plot.plot3d.shapes2 import tetrahedron, Sage has already made tetrahedron accessible via its startup scripts. So when you type tetrahedron?, Sage finds the function in its global registry and shows the docstring — even though you didn’t explicitly import it. Why import ... Works but from ... import tetrahedron Fails The module sage.plot.plot3d.shapes2 exists, but it doesn’t expose tetrahedron directly via its __init__.py.

ortollj gravatar imageortollj ( 2025-09-09 13:34:36 +0200 )edit
1

Perhaps better than search_src('def tetrahedron') would be search_def('tetrahedron'): search_def is designed to search for where objects are defined.

John Palmieri gravatar imageJohn Palmieri ( 2025-09-25 23:02:31 +0200 )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: 2025-09-09 10:00:50 +0200

Seen: 13,482 times

Last updated: Sep 25