當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。