_import('matplotlib') # Installs matplotlib and imports into global space if not available.
import os
import os.path as osp
import importlib
import pip
PIP10 = int(pip.__version__.split('.')[0]) == 10
if PIP10:
from pip._internal import main as pip_main
else:
from pip import main as pip_main
def pip_install(*packages, upgrade = False):
args = [
'install',
'--upgrade' if upgrade else ''
] + list(packages)
args = [arg for arg in args if bool(arg)]
pip_main(args)
def _import(package, install = True):
try:
importlib.import_module(package)
except ImportError as e:
if not install:
raise
else:
pip_install(package)
_import(package, install = False)