def is_in_virtualenv():
    """
    Check virtualenv membership dynamically

    :return: True or false depending on whether we are in a regular virtualenv or not
    :rtype: bool
    """

    pipenv_active = os.environ.get("PIPENV_ACTIVE", False)
    virtual_env = None
    use_system = False
    ignore_virtualenvs = bool(os.environ.get("PIPENV_IGNORE_VIRTUALENVS", False))

    if not pipenv_active and not ignore_virtualenvs:
        virtual_env = os.environ.get("VIRTUAL_ENV")
        use_system = bool(virtual_env)
    return (use_system or virtual_env) and not (pipenv_active or ignore_virtualenvs)
Check virtualenv membership dynamically

    :return: True or false depending on whether we are in a regular virtualenv or not
    :rtype: bool