aboutsummaryrefslogtreecommitdiff
path: root/ctec/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'ctec/__init__.py')
-rw-r--r--ctec/__init__.py17
1 files changed, 17 insertions, 0 deletions
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)