Yes the try: except ImportError: technique does work
For the other one, you really meant to say

:
Code:
import sys
in_calibre = hasattr(sys, 'extensions_location')
Although, IMO, maybe looking for calibre_basename, calibre_function, or calibre_module is better since more obvious what you are looking for? (extensions_location is a bit general).