Skip to content

ImportError: "Please install google-generativeai and 'vertexai' to use Google's API" Despite Both Libraries Being Installed. #5132

Closed
@parth-sidgs

Description

What happened?

While running the script autogen_code_reviewer.py that utilizes the autogen library, the following error occurred:
ImportError: Please install google-generativeai and 'vertexai' to use Google's API.

This error persists even after installing both google-generativeai and vertexai in the virtual environment. I verified both libraries using the pip show command. Also, the script was activated in a fresh virtual environment with all packages installed. The same code was running 2 days back, but suddenly throwing the above error.

What did you expect to happen?

The script should have executed without throwing the ImportError, as the necessary dependencies (google-generativeai and vertexai) were installed successfully. Specifically:

  1. The AssistantAgent initialization should proceed without issues.
  2. The script should begin generating and reviewing code as expected.

How can we reproduce it (as minimally and precisely as possible)?

  1. Activate the virtual environment.

  2. Install the necessary dependencies:
    pip install pyautogen google-generativeai vertexai autogen-agentchat~=0.2

  3. Run the following script:

import autogen
from autogen import AssistantAgent, UserProxyAgent

config_list = [
{
"model": "gemini-1.5-pro-002",
"api_type": "google",
"project_id": "my_project_id",
"location": "my_location"
}
]

code_generator = AssistantAgent(
name="code_generator",
llm_config={
"config_list": config_list,
"seed": 42,
"temperature": 0.7
},
system_message="""You are an expert code generator. Generate clean and well-documented code based on the requirements provided.""",
max_consecutive_auto_reply=2
)

Note: I authenticated with GCP using :gcloud auth application-default login, to use the Gemini model

AutoGen version

pyautogen version : 0.7.1

Which package was this bug in

Core

Model used

gemini-1.5-pro-002

Python version

3.12.5

Operating system

Windows 11

Any additional info you think would be helpful for fixing this bug

No response

Metadata

Assignees

No one assigned

    Labels

    0.2Issues which are related to the pre 0.4 codebaseneeds-triage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions