[Python] Gemini AI error - "AttributeError: module 'google.generativeai' has no attribute...

Discussão em 'Python' iniciado por Stack, Maio 27, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a script in Jupyter for testing Google Gemini AI model.

    import google.generativeai as genai
    import os

    # genai.configure(api_key="API Key")

    model = genai.GenerativeModel('gemini-pro')
    response = model.generate_content('Please summarise this document: ...')

    print(response.text)


    I'm getting this error:

    AttributeError
    Traceback (most recent call last)
    Input In [2], in <cell line: 6>()
    2 import os
    4 # genai.configure(api_key=os.environ['API_KEY'])
    ----> 6 model = genai.GenerativeModel('gemini-pro')
    7 response = model.generate_content('Please summarise this document: ...')
    9 print(response.text)

    AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel'


    I tried:

    • Re-installing package - python3.11 -m pip install google-generativeai
    • Checked whether the class named GenerativeModel existed in my installed package source code but it didn't help.

    Python and package versions:

    • python: 3.11.7
    • google-generativeai=0.5.1

    Continue reading...

Compartilhe esta Página