Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

AttributeError: google.generativeai.models has no attribute 'Type' on macOS #693

@ripred

Description

@ripred

Description of the bug:

Describe the bug

I'm encountering an AttributeError when trying to use the google-generativeai library on macOS. The error occurs even in a clean virtual environment and with the latest version of the library. The library seems unable to find the Type enum within the models module.

Steps to reproduce

  1. Create a clean Python virtual environment:
    python3.12 -m venv .venv312  # Or use your preferred Python version
    source .venv312/bin/activate
  2. Install the google-generativeai library:
    pip install google-generativeai
  3. Create a simple Python script (test_genai.py) with the following content:
    #!/usr/bin/env python3
    import google.generativeai.models as glm
    
    print(glm.Type.OBJECT)
    print(glm.Type.STRING)
  4. Run the script:
    python test_genai.py

Expected behavior

The script should print the enum values:

<Type.OBJECT: 'OBJECT'>
<Type.STRING: 'STRING'>

Actual behavior

The script raises an AttributeError:

Traceback (most recent call last):
File "/Users/trent/dev/gemini/arduino_project_manager/test_genai.py", line 4, in
print(glm.Type.OBJECT)
^^^^^^^^
AttributeError: module 'google.generativeai.models' has no attribute 'Type'

Environment

  • Operating System: macOS [Your macOS Version - e.g., Sonoma 14.3.1]
  • Python Version: [Your Python Version - e.g., 3.12.2] (Get this from python3.12 --version inside the venv). Also mention you tried 3.10.
  • google-generativeai Version: [Version from pip show google-generativeai inside the venv - e.g., 0.8.4]
  • Virtual Environment: Yes (and I tried multiple Python versions)

Additional context

I have tried the following troubleshooting steps:

  • Uninstalled and reinstalled google-generativeai multiple times.
  • Created a completely clean virtual environment.
  • Tried different Python versions (3.10, 3.12).
  • Checked for conflicting google-* packages in the virtual environment (none found).
  • The same error occurred using a fresh virtual environment with Python 3.12

A workaround is to downgrade to google-generativeai==0.4.0 and use string literals ("object", "string") instead of glm.Type.OBJECT in the tool definitions. However, this is not ideal, as it prevents using newer features of the library.

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions