方法1
try:
import extension_magic_module
except ImportError:
pass
else:
handle_extension_magic_module()
方法二:
http://stackoverflow.com/questions/14050281/how-to-check-if-a-python-module-exists-without-importing-it
import imp
try:
imp.find_module('eggs')
found = True
except ImportError:
found = False
方法3:
python -c "import abc"