本文整理匯總了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