From 1cf5e68c25c0505194f23d4018e29767d3b519dd Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sat, 27 Feb 2021 17:14:38 -0700 Subject: fetch inboxes --- ctec/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'ctec/__init__.py') diff --git a/ctec/__init__.py b/ctec/__init__.py index 9f109cb..4b91645 100644 --- a/ctec/__init__.py +++ b/ctec/__init__.py @@ -1 +1,18 @@ +import importlib +import subprocess +import sys + VERSION = (1,0,0) + +def import_or_install(name, pypi_name=None): + if pypi_name is None: + pypi_name = name + try: + return importlib.import_module(name) + except ImportError: + try: + subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', pypi_name]) + except subprocess.CalledProcessError: + subprocess.check_call([sys.executable, '-m', 'ensurepip']) + subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', pypi_name]) + return importlib.import_module(name) -- cgit v1.2.3