Heh. That's an approach I hadn't thought of.
Unfortunately, it's not a complete solution, because indirect imports will still not be logged.

We could move that duplicated code to a new, import-free module (say, sympy.core.pythonversion), and import that. Also, have s.c.compatibility import s.c.pythonversion of course.
Pro: if we ever change the version checking logic, we don't need to touch two pieces of code.
Con: If diagnose_imports ever needs more features from s.c.compatibility than today, that code would have to be moved around as well.
Neutral: Number of dependencies doesn't change, currently diagnose_imports depends on version checking logic, after that the way functionality is split across files in sympy.core.compatibility is restricted by the needs of diagnose_imports.
Pro: The new setup would be a less strict dependency (moving code to a different file is easier to fix).
Con: exec would indeed be a lot of code to fix a relatively small problem.

Dunno, it's a narrow judgement call. I'd be fine with either.