Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Errors with Import "vertexai", "vertexai.generative_models" could not be resolved

I keep getting these errors in python trying to use the gemini model, pictured below, and really stumped as I've followed the pip install and google auth steps and tried doing it both with and without a virtual env but haven't been able to resolve. I also tried it in node.js, in which it worked perfectly, but I wanted to use python to build a project with this. If anyone knows how to fix this, thanks in advance!

Screenshot 2024-07-16 at 8.10.38 AM.png

0 1 2,208
1 REPLY 1

Hi @rohankansal,

Welcome to Google Cloud Community!

The module "vertexai.generative_models" provides the Python interface for interacting with Vertex AI's Generative AI models and it seems that this is missing from your library. You also mentioned that you have already installed the Vertex AI SDK by running its pip command. With this, could you try verifing the installation by running the following code:

import vertexai
from vertexai.generative_models import TextGenerationModel
 
If no error occurs, your installation is successful.
 
In addition, you may check the following configuration in your environment that may help:
  • Virtual Environments: If you're using virtual environments, check if you have activated the correct one where the Vertex AI SDK is installed.
  • Project Dependencies: If your project has a requirements.txt file, make sure it includes "google-cloud-aiplatform".
If you're using specific model imports, you may need to import specific model classes from "vertexai.generative_models" depending on the model you're working with. For example:
from vertexai.generative_models import TextGenerationModel  
# or
from vertexai.generative_models import ImageGenerationModel​
 
Hope this helps.