aboutsummaryrefslogtreecommitdiff
path: root/ctec/__init__.py
blob: 4b91645ec48653b4caea36783d91a815016fb0cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)