def check_requirements(self, show_warning=False):
req_path = self.get_requirements() or self.path
req_file = 'requirements.txt'
missing = []
try:
with open(os.path.join(req_path, req_file), 'r') as f:
import pip
installed_packages = [re.sub(r'-', '_', package.project_name.lower()) for package in pip.get_installed_distributions(local_only=True)]
for line in f.read().splitlines():
pkg = re.sub(r'-', '_', re.sub(r'^([\w-]+).*$', r'\1', line).lower())
if not pkg in installed_packages:
missing.append(pkg)
if missing and install_requirements:
try:
action("Auto-installing missing Python modules...")
pquery(['pip', 'install', '-q', '-r', os.path.join(req_path, req_file)])
missing = []
except ProcessException:
warning("Unable to auto-install required Python modules.")
except (IOError, ImportError, OSError):
pass
if missing:
err = (
"-----------------------------------------------------------------\n"
"The mbed OS tools in this program require the following Python modules: %s\n"
"You can install all missing modules by running \"pip install -r %s\" in \"%s\"" % (', '.join(missing), req_file, req_path))
if os.name == 'posix':
err += "\nOn Posix systems (Linux, Mac, etc) you might have to switch to superuser account or use \"sudo\""
if show_warning:
warning(err)
else:
error(err, 1)
# Routines after cloning mbed-os
评论列表
文章目录