本文整理汇总了Python中pip._internal.utils.misc.get_installed_distributions方法的典型用法代码示例。如果您正苦于以下问题:Python misc.get_installed_distributions方法的具体用法?Python misc.get_installed_distributions怎么用?Python misc.get_installed_distributions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._internal.utils.misc
的用法示例。
在下文中一共展示了misc.get_installed_distributions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collect_loaded_packages
# 需要导入模块: from pip._internal.utils import misc [as 别名]
# 或者: from pip._internal.utils.misc import get_installed_distributions [as 别名]
def collect_loaded_packages() -> List[Tuple[str, str]]:
"""
Return the currently loaded package names and their versions.
"""
dists = get_installed_distributions()
get_dist_files = DistFilesFinder()
file_table = {}
for dist in dists:
for file in get_dist_files(dist):
file_table[file] = dist
used_dists = set()
# we greedily load all values to a list to avoid weird
# "dictionary changed size during iteration" errors
for module in list(sys.modules.values()):
try:
dist = file_table[module.__file__]
except (AttributeError, KeyError):
continue
used_dists.add(dist)
return sorted((dist.project_name, dist.version) for dist in used_dists)
示例2: create_package_set_from_installed
# 需要导入模块: from pip._internal.utils import misc [as 别名]
# 或者: from pip._internal.utils.misc import get_installed_distributions [as 别名]
def create_package_set_from_installed(**kwargs):
# type: (**Any) -> Tuple[PackageSet, bool]
"""Converts a list of distributions into a PackageSet.
"""
# Default to using all packages installed on the system
if kwargs == {}:
kwargs = {"local_only": False, "skip": ()}
package_set = {}
problems = False
for dist in get_installed_distributions(**kwargs):
name = canonicalize_name(dist.project_name)
try:
package_set[name] = PackageDetails(dist.version, dist.requires())
except RequirementParseError as e:
# Don't crash on broken metadata
logging.warning("Error parsing requirements for %s: %s", name, e)
problems = True
return package_set, problems
示例3: create_package_set_from_installed
# 需要导入模块: from pip._internal.utils import misc [as 别名]
# 或者: from pip._internal.utils.misc import get_installed_distributions [as 别名]
def create_package_set_from_installed(**kwargs):
# type: (**Any) -> Tuple[PackageSet, bool]
"""Converts a list of distributions into a PackageSet.
"""
# Default to using all packages installed on the system
if kwargs == {}:
kwargs = {"local_only": False, "skip": ()}
package_set = {}
problems = False
for dist in get_installed_distributions(**kwargs):
name = canonicalize_name(dist.project_name)
try:
package_set[name] = PackageDetails(dist.version, dist.requires())
except RequirementParseError as e:
# Don't crash on broken metadata
logger.warning("Error parsing requirements for %s: %s", name, e)
problems = True
return package_set, problems
示例4: create_package_set_from_installed
# 需要导入模块: from pip._internal.utils import misc [as 别名]
# 或者: from pip._internal.utils.misc import get_installed_distributions [as 别名]
def create_package_set_from_installed(**kwargs):
# type: (**Any) -> PackageSet
"""Converts a list of distributions into a PackageSet.
"""
# Default to using all packages installed on the system
if kwargs == {}:
kwargs = {"local_only": False, "skip": ()}
retval = {}
for dist in get_installed_distributions(**kwargs):
name = canonicalize_name(dist.project_name)
retval[name] = PackageDetails(dist.version, dist.requires())
return retval
示例5: create_package_set_from_installed
# 需要导入模块: from pip._internal.utils import misc [as 别名]
# 或者: from pip._internal.utils.misc import get_installed_distributions [as 别名]
def create_package_set_from_installed(**kwargs):
# type: (**Any) -> PackageSet
"""Converts a list of distributions into a PackageSet.
"""
# Default to using all packages installed on the system
if kwargs == {}:
kwargs = {"local_only": False, "skip": ()}
package_set = {}
for dist in get_installed_distributions(**kwargs):
name = canonicalize_name(dist.project_name)
package_set[name] = PackageDetails(dist.version, dist.requires())
return package_set
示例6: check_deps
# 需要导入模块: from pip._internal.utils import misc [as 别名]
# 或者: from pip._internal.utils.misc import get_installed_distributions [as 别名]
def check_deps():
# Fail if the 'co3' module is installed, this supersedes it
packages = get_installed_distributions(local_only=True)
# For each EggInfoDistribution, find its metadata
for pkg in packages:
try:
distro = get_distribution(pkg.project_name)
if distro.project_name == 'co3':
print("This package replaces the 'co3' distribution. Please 'pip uninstall co3' first.")
sys.exit(1)
except DistributionNotFound:
pass