本文整理匯總了Python中pip.get_installed_distributions方法的典型用法代碼示例。如果您正苦於以下問題:Python pip.get_installed_distributions方法的具體用法?Python pip.get_installed_distributions怎麽用?Python pip.get_installed_distributions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pip
的用法示例。
在下文中一共展示了pip.get_installed_distributions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: collect_loaded_packages
# 需要導入模塊: import pip [as 別名]
# 或者: from pip 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: collect_environment
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def collect_environment(self, overwrite_variables=None):
import socket
import os
import pip
import platform
env = {}
if not overwrite_variables:
overwrite_variables = {}
import aetros
env['aetros_version'] = aetros.__version__
env['python_version'] = platform.python_version()
env['python_executable'] = sys.executable
env['hostname'] = socket.gethostname()
env['variables'] = dict(os.environ)
env['variables'].update(overwrite_variables)
if 'AETROS_SSH_KEY' in env['variables']: del env['variables']['AETROS_SSH_KEY']
if 'AETROS_SSH_KEY_BASE64' in env['variables']: del env['variables']['AETROS_SSH_KEY_BASE64']
env['pip_packages'] = sorted([[i.key, i.version] for i in pip.get_installed_distributions()])
self.set_system_info('environment', env)
示例3: _save_pip_list
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def _save_pip_list(self, tar):
'''Dump a pip list containing packages and versions.
:param dest: unicode -- directory of dumped pip list
:param tar: tarfile object -- tar where pip list dump will be added
'''
pkgs = pip.get_installed_distributions()
sorted_pkgs = sorted(pkgs, key=lambda pkg: pkg._key)
sorted_pkg_names = [str(pkg) for pkg in sorted_pkgs]
pip_list_file = os.path.join(self.tar_dest, 'pip_list.txt')
with open(pip_list_file, 'w') as pip_file:
pip_file.write('\n'.join(sorted_pkg_names))
self._add_file_to_tar(self.tar_dest, 'pip_list.txt', tar)
os.remove(pip_list_file)
return sorted_pkgs
示例4: _save_pip_list
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def _save_pip_list(self, tar):
'''Dump a pip list, containing packages and versions.
:param dest: unicode -- directory of dumped pip list
:param tar: tarfile object -- tar where pip list dump will be added
'''
pkgs = pip.get_installed_distributions()
sorted_pkgs = sorted(pkgs, key=lambda pkg: pkg._key)
sorted_pkg_names = [str(pkg) for pkg in sorted_pkgs]
pip_list_file = os.path.join(self.tar_dest, 'pip_list.txt')
with open(pip_list_file, 'w') as pip_file:
pip_file.write('\n'.join(sorted_pkg_names))
self._add_file_to_tar(self.tar_dest, 'pip_list.txt', tar)
os.remove(pip_list_file)
return sorted_pkgs
示例5: check_dependency
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def check_dependency():
list_deps = []
missing_deps = []
with open('requirements.txt') as f:
list_deps = f.read().splitlines()
pip_list = sorted([(i.key) for i in pip.get_installed_distributions()])
for req_dep in list_deps:
if req_dep not in pip_list:
missing_deps.append(req_dep)
if missing_deps:
print "You are missing a module for Datasploit. Please install them using: "
print "pip install -r requirements.txt"
sys.exit()
示例6: can_use_gpu
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def can_use_gpu():
# Check that 'tensorflow-gpu' is installed on the current code-env
import pip
installed_packages = pip.get_installed_distributions()
return "tensorflow-gpu" in [p.project_name for p in installed_packages]
###################################################################################################################
## FILES LOGIC
###################################################################################################################
示例7: _generate_software_info
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def _generate_software_info(self):
os_version = self._prepare_for_json(platform.platform())
installed_packages = [self._prepare_for_json(pack) for pack in pip.get_installed_distributions()]
output = self._run_external_cmd("dpkg-query --list | grep indy")
indy_packages = output.split(os.linesep)
return {
"Software": {
"OS_version": os_version,
"Installed_packages": installed_packages,
# TODO add this field
"Indy_packages": self._prepare_for_json(indy_packages),
}
}
示例8: get_uninstalled_project_names
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def get_uninstalled_project_names():
try:
import pip
pkg_set = set(KNOWN_PKG_LIST)
pathmeta_list = pip.get_installed_distributions()
installed_set = set([meta.project_name for meta in pathmeta_list])
uninstalled_set = pkg_set.difference(installed_set)
uninstalled_list = list(uninstalled_set)
except Exception as ex:
print(ex)
uninstalled_list = KNOWN_PKG_LIST
return uninstalled_list
示例9: get_pip_installed
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def get_pip_installed():
try:
import pip
pypkg_list = [item.key for item in pip.get_installed_distributions()]
return pypkg_list
except ImportError:
#out, err, ret = shell('pip list')
#if ret == 0:
# pypkg_list = [_.split(' ')[0] for _ in out.split('\n')]
return []
示例10: show_version
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def show_version(scoring_version):
''' Python version and library versions '''
swrite('\n=== VERSIONS ===\n\n')
# Scoring program version
swrite("Scoring program version: " + str(scoring_version) + "\n\n")
# Python version
swrite("Python version: " + version + "\n\n")
# Give information on the version installed
swrite("Versions of libraries installed:\n")
map(swrite, sorted(["%s==%s\n" % (i.key, i.version) for i in lib()]))
示例11: show_version
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def show_version():
# Python version and library versions
swrite('\n=== VERSIONS ===\n\n')
# Python version
swrite("Python version: " + version + "\n\n")
# Give information on the version installed
swrite("Versions of libraries installed:\n")
map(swrite, sorted(["%s==%s\n" % (i.key, i.version) for i in lib()]))
示例12: _safe_dist
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def _safe_dist():
for p in pip.get_installed_distributions():
try:
yield p.key, p.version
except Exception: # pragma nocover
pass
示例13: log_running_python_versions
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def log_running_python_versions():
logging.info("Python version: " + str(sys.version) + ", " + str(sys.version_info)) # () required in Python 3.
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
logging.info("Installed Python modules: " + str(installed_packages_list))
示例14: check_deps
# 需要導入模塊: import pip [as 別名]
# 或者: from pip 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
示例15: check_depdendencies
# 需要導入模塊: import pip [as 別名]
# 或者: from pip import get_installed_distributions [as 別名]
def check_depdendencies():
"""
Makes sure that all required dependencies are installed in the exact version
(as specified in requirements.txt)
"""
# Get installed packages
installed_packages = pip.get_installed_distributions(local_only=False)
installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
# Now check if each package specified in requirements.txt is actually installed
deps_filename = os.path.join(ROOT_INSTALL_PATH, "requirements.txt")
with open(deps_filename, "r") as f:
for dep in f.read().split():
if not dep.lower() in installed_packages_list:
raise SystemCheckError("Required dependency %s is not installed. Please run 'pip install -e .'" % dep)