def import_with_install(package_import_name, package_install_name=None):
    """
    Helps import 'package'. If its not present, it will be installed using 'pip' and a re-import will be attempted, which should succeed if the package was imported correctly

    :param package_import_name: name of package to be installed using pip, str
    :param package_install_name: name of package to be imported. Default is None, which means package can be imported with the same name as used for installation. If not, this parameter can be used to specify a different import name.
    :return: imported package
    """
    package_install_name = (package_install_name if package_install_name is not
        None else package_import_name)
    try:
        return __import__(package_import_name)
    except ImportError:
        print(f'Installing package {package_import_name} via pip...')
        import subprocess
        import sys
        subprocess.check_call([sys.executable, '-m', 'pip', 'install',
            package_install_name])
        return __import__(package_import_name)
