当前位置: 首页>>代码示例>>Python>>正文


Python pkgutil.find_loader方法代码示例

本文整理汇总了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. 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:26,代码来源:common.py

示例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 
开发者ID:mars-project,项目名称:mars,代码行数:19,代码来源:utils.py

示例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 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:23,代码来源:_testing_utils.py

示例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 
开发者ID:Erotemic,项目名称:ubelt,代码行数:25,代码来源:util_import.py

示例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 
开发者ID:mmp2,项目名称:megaman,代码行数:19,代码来源:utils.py

示例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 
开发者ID:IDSIA,项目名称:sacred,代码行数:10,代码来源:utils.py

示例7: module_exists

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def module_exists(name):
    return find_loader(name) 
开发者ID:rmodrak,项目名称:seisflows,代码行数:4,代码来源:tools.py

示例8: package_exists

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import find_loader [as 别名]
def package_exists(name):
    return find_loader(name) 
开发者ID:rmodrak,项目名称:seisflows,代码行数:4,代码来源:tools.py

示例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 
开发者ID:spyder-ide,项目名称:spyder-unittest,代码行数:15,代码来源:runnerbase.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_pkgutil.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_pkgutil.py

示例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] 
开发者ID:qkitgroup,项目名称:qkit,代码行数:6,代码来源:S16_available_modules.py

示例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 
开发者ID:dagster-io,项目名称:dagster,代码行数:15,代码来源:__init__.py

示例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)) 
开发者ID:perslev,项目名称:MultiPlanarUNet,代码行数:11,代码来源:test_imports.py

示例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 
开发者ID:NeuromorphicProcessorProject,项目名称:snn_toolbox,代码行数:7,代码来源:utils.py


注:本文中的pkgutil.find_loader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。