def install_package(package: str, upgrade: bool=True,
target: Optional[str]=None) -> bool:
"""Install a package on PyPi. Accepts pip compatible package strings.
Return boolean if install successful.
"""
# Not using 'import pip; pip.main([])' because it breaks the logger
with INSTALL_LOCK:
if check_package_exists(package, target):
return True
_LOGGER.info('Attempting install of %s', package)
args = [sys.executable, '-m', 'pip', 'install', '--quiet', package]
if upgrade:
args.append('--upgrade')
if target:
args += ['--target', os.path.abspath(target)]
try:
return subprocess.call(args) == 0
except subprocess.SubprocessError:
_LOGGER.exception('Unable to install pacakge %s', package)
return False
评论列表
文章目录