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
- Create a clean Python virtual environment:
python3.12 -m venv .venv312 # Or use your preferred Python version
source .venv312/bin/activate
- Install the
google-generativeai library:
pip install google-generativeai
- 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)
- Run the script:
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
Description of the bug:
Describe the bug
I'm encountering an
AttributeErrorwhen trying to use thegoogle-generativeailibrary 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 theTypeenum within themodelsmodule.Steps to reproduce
google-generativeailibrary:test_genai.py) with the following content: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
python3.12 --versioninside the venv). Also mention you tried 3.10.pip show google-generativeaiinside the venv - e.g., 0.8.4]Additional context
I have tried the following troubleshooting steps:
google-generativeaimultiple times.google-*packages in the virtual environment (none found).A workaround is to downgrade to
google-generativeai==0.4.0and use string literals ("object", "string") instead ofglm.Type.OBJECTin 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