<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _initialize_client_from_environment():
    ''' Initialize a KeenClient instance using environment variables. '''
    global _client, project_id, write_key, read_key, master_key, base_url

    if _client is None:
        # check environment for project ID and keys
        project_id = project_id or os.environ.get("KEEN_PROJECT_ID")
        write_key = write_key or os.environ.get("KEEN_WRITE_KEY")
        read_key = read_key or os.environ.get("KEEN_READ_KEY")
        master_key = master_key or os.environ.get("KEEN_MASTER_KEY")
        base_url = base_url or os.environ.get("KEEN_BASE_URL")

        if not project_id:
            raise InvalidEnvironmentError("Please set the KEEN_PROJECT_ID environment variable or set keen.project_id!")

        _client = KeenClient(project_id,
                             write_key=write_key,
                             read_key=read_key,
                             master_key=master_key,
                             base_url=base_url)