Closed DronePower69 closed 1 month ago
Hi @DronePower69
It worked fine when I tested it in Google Colab. You can check out the gist here. Please try running the code from the provided link.
Thanks
google
is a namespace package. They have some strange behaviors.
Hitting this as well. Repro is quite simple, you just need to use a version of python < 3.9
mkdir ~/dev/gemini_repro
cd ~/dev/gemini_repro
python -m venv venv
source venv/bin/activate
python -V
# Python 3.8.17
pip install --upgrade pip
pip install google-generativeai
// Run the sample snippet from readme
However I found by using the same version of python that is in the collab notebook, the sample snippet works as advertised. Collab notebook version is 3.10.12 (you can find this by running ! python -V
in a cell in the notebook)
I also tested on python 3.9.16 and 3.12.2, and those work as expected. I'll leave it to the google team to bisect where the minimum version is.
So @DronePower69 , try upgrading python. I use pyenv for this and that works really well. You'd do something like this:
pyenv install 3.10.12
mkdir ~/dev/gemini_project
echo "3.10.12" > ~/dev/gemini_project/.python-version
cd ~/dev/gemini_project
python -m venv venv
source venv/bin/activate
python -V
# verify that 3.10.12 is printed out
Considering you have a version of Python 3.8 or below, you need to use a version of Python 3.9 or higher. I had a problem with the 3.8 version. I've tested with Python 3.10.15, it works flawlessly.
@sukruburakcetin, yes, we don't support Python < 3.9. Please upgrade your python, I bet that will fix it.
Description of the bug:
Using the following code:
import os
import google.generativeai as genai
I tried every method there was.
I even did:
Please help me with this
Actual vs expected behavior:
Working in colab, but giving the error ; "ModuleNotFoundError: No module named 'google.generativeai'"
Any other information you'd like to share?
import os import google.generativeai as genai
GOOGLE_API_KEY="---" genai.configure(api_key=os.environ[GOOGLE_API_KEY])
prompt = input("You: ")
Generate a response
model = genai.GenerativeModel("gemini-1.5-flash") response = model.generate_content(prompt) print(response.text)