本文整理汇总了Python中pkgutil.find_loader方法的典型用法代码示例。如果您正苦于以下问题:Python pkgutil.find_loader方法的具体用法?Python pkgutil.find_loader怎么用?Python pkgutil.find_loader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkgutil
的用法示例。
在下文中一共展示了pkgutil.find_loader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_modules_installed
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def check_modules_installed():
reqs = []
os_type = get_os_type()
# reqs = [["module_name", "package_name"], [...]]
if os_type == OS_LINUX:
reqs = [["cryptography", "cryptography"], ["sctp","pysctp"]]
if os_type == OS_MACOSX:
reqs = [["cryptography", "cryptography"]]
if os_type == OS_WINDOWS:
reqs = [["cryptography", "cryptography"], ["win32file","pywin32"]]
if os_type == OS_FREEBSD:
reqs = [["cryptography", "cryptography"]]
allinstalled = True
for m in reqs:
if not pkgutil.find_loader(m[0]):
allinstalled = False
internal_print("The following python modules were not installed: {0}".format(m[1]), -1)
return allinstalled
# get os type. No need to import 'platform' in every module this way.
示例2: lazy_import
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def lazy_import(name, package=None, globals=None, locals=None, rename=None):
rename = rename or name
prefix_name = name.split('.', 1)[0]
class LazyModule(object):
def __getattr__(self, item):
real_mod = importlib.import_module(name, package=package)
if globals is not None and rename in globals:
globals[rename] = real_mod
elif locals is not None:
locals[rename] = real_mod
return getattr(real_mod, item)
if pkgutil.find_loader(prefix_name) is not None:
return LazyModule()
else:
return None
示例3: module_importable
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def module_importable(module):
"""Without importing it, returns whether python module is importable.
Args:
module (string): Name of module.
Returns:
bool
"""
import sys
if sys.version_info >= (3, 4):
from importlib import util
plug_spec = util.find_spec(module)
else:
import pkgutil
plug_spec = pkgutil.find_loader(module)
if plug_spec is None:
return False
else:
return True
示例4: _pkgutil_modname_to_modpath
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def _pkgutil_modname_to_modpath(modname): # nocover
"""
faster version of :func:`_syspath_modname_to_modpath` using builtin python
mechanisms, but unfortunately it doesn't play nice with pytest.
Example:
>>> # xdoctest: +SKIP
>>> modname = 'xdoctest.static_analysis'
>>> _pkgutil_modname_to_modpath(modname)
...static_analysis.py
>>> # xdoctest: +REQUIRES(CPython)
>>> _pkgutil_modname_to_modpath('_ctypes')
..._ctypes...
Ignore:
>>> _pkgutil_modname_to_modpath('cv2')
"""
import pkgutil
loader = pkgutil.find_loader(modname)
if loader is None:
raise Exception('No module named {} in the PYTHONPATH'.format(modname))
modpath = loader.get_filename().replace('.pyc', '.py')
return modpath
示例5: _check_backend
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def _check_backend(backend):
def decorator(func):
def wrapper(*args,**kwargs):
import warnings
warnings.warn(
'Be careful in using megaman.plotter modules'
' API will change in the next release.',
FutureWarning
)
import pkgutil
package = pkgutil.find_loader(backend)
if package is not None:
return func(*args,**kwargs)
else:
raise ImportError('plotting backend {} not installed'.format(backend))
return wrapper
return decorator
示例6: module_exists
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def module_exists(modname):
"""Checks if a module exists without actually importing it."""
try:
return pkgutil.find_loader(modname) is not None
except ImportError:
# TODO: Temporary fix for tf 1.14.0.
# Should be removed once fixed in tf.
return True
示例7: module_exists
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def module_exists(name):
return find_loader(name)
示例8: package_exists
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def package_exists(name):
return find_loader(name)
示例9: is_installed
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def is_installed(cls):
"""
Check whether test framework is installed.
This function tests whether self.module is installed, but it does not
import it.
Returns
-------
bool
True if framework is installed, False otherwise.
"""
return find_spec_or_loader(cls.module) is not None
示例10: test_find_loader_missing_module
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def test_find_loader_missing_module(self):
name = 'totally bogus'
loader = pkgutil.find_loader(name)
self.assertIsNone(loader)
示例11: test_find_loader_avoids_emulation
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def test_find_loader_avoids_emulation(self):
with check_warnings() as w:
self.assertIsNotNone(pkgutil.find_loader("sys"))
self.assertIsNotNone(pkgutil.find_loader("os"))
self.assertIsNotNone(pkgutil.find_loader("test.support"))
self.assertEqual(len(w.warnings), 0)
示例12: module_available
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def module_available(self, module_name):
if module_name not in self.available_modules:
self.available_modules[module_name] = bool(find_loader(module_name))
return self.available_modules[module_name]
示例13: is_module_available
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def is_module_available(module_name):
if sys.version_info <= (3, 3):
# python 3.3 and below
import pkgutil
loader = pkgutil.find_loader(module_name)
elif sys.version_info >= (3, 4):
# python 3.4 and above
import importlib
loader = importlib.util.find_spec(module_name)
return loader is not None
示例14: test_modules_exist
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def test_modules_exist(self):
""" Check if needed modules exist (are visible to Python) """
for mod in self.needed_mods:
self.assertIsNot(pkgutil.find_loader(mod), None,
msg="Could not find loader for needed package "
"'{}' - This could indicate that the package "
"is not installed or is not visible to the "
"current Python interpreter "
"session.".format(mod))
示例15: is_module_installed
# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def is_module_installed(mod):
if sys.version_info[0] < 3:
return pkgutil.find_loader(mod) is not None
else:
return importlib.util.find_spec(mod) is not None