def name_from_req(req):
    """
    Get the distribution name from a requirement.

    :type req: packaging.requirements.Requirement
    :rtype: str
    """
    return req.name if hasattr(req, 'name') else req.key
