Yes. You can wrap the import statement in a try - except block. It is commonly used for backward compatibility. For example, importing a return module as the required module. Thus, the rest of the code may not pay attention to which module is actually used.
source share