def has_module(name):
"""
Check if the Python module 'name' is available.
Parameters
----------
name : str
The name of the Python module, as used in an import instruction.
This function uses ideas from this Stack Overflow question:
http://stackoverflow.com/questions/14050281/
Returns
-------
b : bool
True if the module exists, or False otherwise.
"""
if sys.version_info > (3, 3):
import importlib.util
return importlib.util.find_spec(name) is not None
elif sys.version_info > (2, 7, 99):
import importlib
return importlib.find_loader(name) is not None
else:
import pkgutil
return pkgutil.find_loader(name) is not None
评论列表
文章目录