Error Importing Imagen SDK

Gemini API & Python newbie here, so please forgive potentially stupid question. Trying to use the Gemini API to generate images using Imagen 3 by following this tutorial: Generate images using Imagen 3 | Gemini API | Google AI for Developers. I am using a clean Python 3.13 install via PowerShell 7.4.5 on a Win11 machine. The python install includes pip, pillow, git and winget (among others). If it matters, everything was installed with PS running with admin privileges.

I am able to successfully follow the tutorial until I get to this line:

import google.generativeai as genai

That line results in the following error:

Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    import google.generativeai as genai
  File "C:\Program Files\Python313\Lib\site-packages\google\generativeai\__init__.py", line 45, in <module>
    from google.generativeai import caching
  File "C:\Program Files\Python313\Lib\site-packages\google\generativeai\caching.py", line 21, in <module>
    from google.generativeai import protos
  File "C:\Program Files\Python313\Lib\site-packages\google\generativeai\protos.py", line 74, in <module>
    from google.ai.generativelanguage_v1beta.types import *
  File "C:\Program Files\Python313\Lib\site-packages\google\ai\generativelanguage_v1beta\__init__.py", line 21, in <module>
    from .services.cache_service import CacheServiceAsyncClient, CacheServiceClient
  File "C:\Program Files\Python313\Lib\site-packages\google\ai\generativelanguage_v1beta\services\cache_service\__init__.py", line 16, in <module>
    from .async_client import CacheServiceAsyncClient
  File "C:\Program Files\Python313\Lib\site-packages\google\ai\generativelanguage_v1beta\services\cache_service\async_client.py", line 50, in <module>
    from google.ai.generativelanguage_v1beta.services.cache_service import pagers
  File "C:\Program Files\Python313\Lib\site-packages\google\ai\generativelanguage_v1beta\services\cache_service\pagers.py", line 41, in <module>
    from google.ai.generativelanguage_v1beta.types import cache_service, cached_content
  File "C:\Program Files\Python313\Lib\site-packages\google\ai\generativelanguage_v1beta\types\__init__.py", line 47, in <module>
    from .discuss_service import (
    ...<7 lines>...
    )
  File "C:\Program Files\Python313\Lib\site-packages\google\ai\generativelanguage_v1beta\types\discuss_service.py", line 22, in <module>
    from google.ai.generativelanguage_v1beta.types import citation, safety
  File "C:\Program Files\Python313\Lib\site-packages\google\ai\generativelanguage_v1beta\types\safety.py", line 224, in <module>
    class SafetySetting(proto.Message):
    ...<48 lines>...
        )
  File "C:\Program Files\Python313\Lib\site-packages\proto\message.py", line 279, in __new__
    file_info.generate_file_pb(new_class=cls, fallback_salt=full_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python313\Lib\site-packages\proto\_file_info.py", line 104, in generate_file_pb
    pool.Add(self.descriptor)
    ~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: Couldn't build proto file into descriptor pool: duplicate symbol 'google.ai.generativelanguage.v1beta.__firstlineno__'

Attempting to follow any subsequent steps are unsuccessful. Any suggestions regarding cause and solution greatly appreciated.

Welcome to the forum.
Apparently your Python is too fresh. See Error in compiling python code google generative ai library - #3 by Susarla_Sai_Manoj

Welcome to the forums!

Also note that, according to that page, Imagen 3 for AI Studio is in private preview. If you’re not in the preview group, and using the preview account or project that has been permitted, then you won’t be able to generate images, and may not even have access to the discovery document with the right information.

And if you are permitted - you’re probably under NDA and should be asking the question to whoever your Google contact is. {:

1 Like

Brilliant! Uninstalled 3.13, installed 3.12.7, problem solved. TY.

I am in the private preview group. When I am on the private preview page with Imagen 3 usage instructions, the Help link goes to this forum. If I am supposed to be posting these questions somewhere else, they don’t make it very clear where that is. Is there a private forum I am supposed to be using? We are a small company & don’t have a Google contact.

I’m using limit tracking on Chrome, safari and Firefox also mostly I’m involved in cryptography tsl encryption on any device coz im google admin

I am, to be honest, surprised that you’re in the Private Preview group, but without the contact that permitted you to that group. Most times I’m in a Private Preview for Google, I have a contact that I get email from about the preview and who is expecting my feedback about the product. Typically it would be the person who emailed you inviting you into the group.

The page itself is public and available to those outside the group. The “Community” link on the left of the page is the generic link that comes here.

But it sounds like @OrangiaNebula solved your issue.