diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py
index d793122b3c4..b468701d525 100644
--- a/src/sage/misc/sageinspect.py
+++ b/src/sage/misc/sageinspect.py
@@ -1281,25 +1281,34 @@ def sage_getfile(obj):
     pos = _extract_embedded_position(d)
     if pos is not None:
         (_, filename, _) = pos
-        return filename
+        # Check if the file is in SAGE_SRC, if it is not, then
+        # it is a build location from a sage-on-fistro build,
+        # and it does not exist anymore. We should not return such a result.
+        from sage.env import SAGE_SRC
+        if filename.startswith(SAGE_SRC):
+            return filename
 
     # The instance case
     if isclassinstance(obj):
         if isinstance(obj, functools.partial):
             return sage_getfile(obj.func)
         return sage_getfile(obj.__class__)  # inspect.getabsfile(obj.__class__)
-    if hasattr(obj, '__init__'):
-        pos = _extract_embedded_position(_sage_getdoc_unformatted(obj.__init__))
-        if pos is not None:
-            (_, filename, _) = pos
-            return filename
 
     # No go? fall back to inspect.
     try:
         sourcefile = inspect.getabsfile(obj)
-    except (TypeError, OSError):  # TypeError happens for Python builtins,
+    except (TypeError, OSError):  # TypeError happens for Python builtins and cython_funtion_or_method
         # OSError happens for objects defined in the shell (having ``__module__ == '__main__'``)
-        return ''
+        try:
+            import sage
+            sourcefile = sage_getfile(eval(obj.__module__))
+        except AttributeError: # could be a method
+            try:
+                sourcefile = sage_getfile(eval(obj.__objclass__.__module__))
+            except (AttributeError, NameError):
+                return ''
+        except (NameError, TypeError, OSError): # We collect many potential errors here as getting the parent module is a small case.
+            return ''
     for suffix in import_machinery.EXTENSION_SUFFIXES:
         if sourcefile.endswith(suffix):
             # TODO: the following is incorrect in meson editable install
@@ -2523,7 +2532,14 @@ def sage_getsourcelines(obj):
             with open(newname) as f:
                 source_lines = f.readlines()
         except OSError:
-            return None
+            try:
+                # The embedded name could be a build location for sage-on-distro
+                # Try the name provided by sage_getfile
+                newname = sage_getfile(obj)
+                with open(newname) as f:
+                    source_lines = f.readlines()
+            except OSError:
+                return None
 
     # It is possible that the source lines belong to the __init__ method,
     # rather than to the class. So, we try to look back and find the class
