import pkg_resources


def installed_using_pip(package: str) -> bool:
    """
    Determine if python package was installed using pip.

    :param package: package name to search for
    :return: True if installed via pip, else False
    """

    pip_install = False
    try:
        pkg = pkg_resources.get_distribution(package)
        if pkg.has_metadata('INSTALLER'):
            if pkg.get_metadata('INSTALLER').strip() == 'pip':
                pip_install = True
    except pkg_resources.DistributionNotFound:
        pass
    except Exception as e:
        print(
            'An unknown error occurred checking if Python package {} is installed '
            'using pip'.format(package)
        )
        print(e)

    return pip_install