from typing import List
from typing import Dict
import importlib


def get_package_versions(
    packages: List[str], *, na_str="not available"
) -> Dict[str, str]:
    """tries to load certain python packages and returns their version

    Args:
        na_str (str): Text to return if package is not available

    Returns:
        dict: Dictionary with version for each package name
    """
    versions: Dict[str, str] = {}
    for name in sorted(packages):
        try:
            module = importlib.import_module(name)
        except ImportError:
            versions[name] = na_str
        else:
            versions[name] = module.__version__  # type: ignore
    return versions