Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy typing issue: Module "google" has no attribute "genai" #61

Open
Ben-Epstein opened this issue Dec 30, 2024 · 5 comments
Open

mypy typing issue: Module "google" has no attribute "genai" #61

Ben-Epstein opened this issue Dec 30, 2024 · 5 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Ben-Epstein
Copy link

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Is this a client library issue or a product issue? We will only be able to assist with issues that pertain to the behaviors of this library. If the issue you're experiencing is due to the behavior of the product itself, please visit the Support page to reach the most relevant engineers.

If the support paths suggested above still do not result in a resolution, please provide the following details.

from google import genai

mypy complains Module "google" has no attribute "genai". I think it's because of your namespacing, google has no __init__.py so it's not a package, it's a namespace. So you can do import google.genai as genai but this isn't great, and also incorrect (any linter will replace it will from google import genai`.

So right now you have to do import google.genai and just use it like that, or add a type: ignore on the import. Or, you can update your docs to do from google.genai import Client

@Ben-Epstein Ben-Epstein added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 30, 2024
@Giom-V
Copy link

Giom-V commented Jan 8, 2025

Are you sure you installed the latest version of the SDK using pip install -U -q google-genai?

from google import genai works in all the cookbook examples, so I don't think there's a problem here.

@Ben-Epstein
Copy link
Author

Thanks @Giom-V, perhaps it was a partial/corrupted install. I rebuilt my venv and mypy is no longer complaining.

@Ben-Epstein
Copy link
Author

Hm @Giom-V the issue has resurfaced

Image Image Image

Any shot it has to do with python3.12?

@Ben-Epstein Ben-Epstein reopened this Jan 15, 2025
@MarkDaoust
Copy link
Collaborator

I rebuilt my venv and mypy is no longer complaining.

Good.

resurfaced

I get a different error:

$ echo "from google import genai" > test.py
$ python -m mypy test.py 
test.py:1: error: Skipping analyzing "google": module is installed, but missing library stubs or py.typed marker  [import-untyped]
test.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Can you give instructions to reproduce it in a clean environment?

Any shot it has to do with python3.12?

Or uv ?

@jayeshp19
Copy link
Contributor

I get a different error:

$ echo "from google import genai" > test.py
$ python -m mypy test.py 
test.py:1: error: Skipping analyzing "google": module is installed, but missing library stubs or py.typed marker  [import-untyped]
test.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

It seems this issue is due to the missing py.typed file. @happy-qiao, could you please review this PR #113?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants