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

error: Module "google.cloud" has no attribute "pubsub_v1" #1059

Closed
coactive-jeffrey opened this issue Jan 11, 2024 · 3 comments · Fixed by #1186
Closed

error: Module "google.cloud" has no attribute "pubsub_v1" #1059

coactive-jeffrey opened this issue Jan 11, 2024 · 3 comments · Fixed by #1186
Assignees
Labels
api: pubsub Issues related to the googleapis/python-pubsub API.

Comments

@coactive-jeffrey
Copy link

from google.cloud import pubsub_v1

Steps to Reproduce:

  1. cd python-pubsub/samples/snippets
  2. python3 -m venv venv && source ./venv/bin/activate
  3. pip install -r requirements.txt
  4. python3 -m pip install mypy
  5. python3 -m mypy --install-types
  6. python3 -m mypy subscriber.py
  7. Observe many occurrences of error: Module "google.cloud" has no attribute "pubsub_v1" [attr-defined]
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Jan 11, 2024
@parthea
Copy link
Contributor

parthea commented Jan 11, 2024

Hi @coactive-jeffrey,

Thanks for providing the detailed reproduction steps. I wasn't able to re-create the same error error: Module "google.cloud" has no attribute "pubsub_v1", however there is an open issue to address a mypy issue with google.cloud.pubsub_v1. See #536. Since I wasn't able to create the error error: Module "google.cloud" has no attribute "pubsub_v1" , I also wonder if this could be an environment specific issue.

Following the steps that you provided, I have the following output

(venv) (base) root@b76d9c22dce0:/python-pubsub/samples/snippets# python3 -m mypy subscriber.py
subscriber.py:35: error: Skipping analyzing "google.cloud": module is installed, but missing library stubs or py.typed marker  [import-untyped]
subscriber.py:107: error: Skipping analyzing "google.cloud.pubsub_v1.types": module is installed, but missing library stubs or py.typed marker  [import-untyped]
subscriber.py:107: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
subscriber.py:363: error: Library stubs not installed for "google.protobuf"  [import-untyped]
subscriber.py:363: note: Hint: "python3 -m pip install types-protobuf"
subscriber.py:363: note: (or run "mypy --install-types" to install all missing stub packages)
subscriber.py:537: error: Returning Any from function declared to return "Subscription"  [no-any-return]
subscriber.py:582: error: Returning Any from function declared to return "Subscription"  [no-any-return]
subscriber.py:765: error: Skipping analyzing "google.cloud.pubsub_v1.subscriber": module is installed, but missing library stubs or py.typed marker  [import-untyped]
Found 6 errors in 1 file (checked 1 source file)

After installing types-protobuf as suggested by the hint, the "google.protobuf" specific error was resolved.
I used pip install "types-protobuf==4.24.0.4" (I'm not using the latest version of types-protobuf as there is an open issue related to it python/typeshed#11254 )

The mypy failures also reduced if you use mypy==0.910 which is the version in noxfile.py. I've opened a bug for the team to update to a newer version of mypy: #1061

(venv) (base) root@b76d9c22dce0:/python-pubsub/samples/snippets# python3 -m mypy subscriber.py
subscriber.py:35: error: Skipping analyzing "google.cloud": found module but no type hints or library stubs
subscriber.py:35: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
subscriber.py:107: error: Skipping analyzing "google.cloud.pubsub_v1.types": found module but no type hints or library stubs
subscriber.py:363: error: Library stubs not installed for "google.protobuf" (or incompatible with Python 3.10)
subscriber.py:363: note: Hint: "python3 -m pip install types-protobuf"
subscriber.py:363: note: (or run "mypy --install-types" to install all missing stub packages)
subscriber.py:537: error: Returning Any from function declared to return "Subscription"
subscriber.py:582: error: Returning Any from function declared to return "Subscription"
subscriber.py:765: error: Skipping analyzing "google.cloud.pubsub_v1.subscriber": found module but no type hints or library stubs
Found 6 errors in 1 file (checked 1 source file)

I found more mypy error messages when I run the command from the root of the repository. It looks like the mypy presubmit checks are not currently running for the samples files. I've opened #1060 for the team to take a look.

(venv) (base) root@b76d9c22dce0:/python-pubsub# python3 -m mypy samples/snippets/subscriber.py
samples/snippets/subscriber.py:107: error: Module "google.cloud.pubsub_v1.types" has no attribute "DeadLetterPolicy"
samples/snippets/subscriber.py:172: error: Module has no attribute "PushConfig"
samples/snippets/subscriber.py:208: error: Module has no attribute "PushConfig"
samples/snippets/subscriber.py:209: error: Module has no attribute "PushConfig"
samples/snippets/subscriber.py:337: error: Module has no attribute "BigQueryConfig"
samples/snippets/subscriber.py:375: error: Module has no attribute "CloudStorageConfig"
samples/snippets/subscriber.py:384: error: Module has no attribute "CloudStorageConfig"
samples/snippets/subscriber.py:454: error: Module has no attribute "PushConfig"
samples/snippets/subscriber.py:456: error: Module has no attribute "Subscription"
samples/snippets/subscriber.py:484: error: Module "google.cloud.pubsub_v1.types" has no attribute "DeadLetterPolicy"
samples/snippets/subscriber.py:484: error: Module "google.cloud.pubsub_v1.types" has no attribute "FieldMask"
samples/snippets/subscriber.py:524: error: Module has no attribute "Subscription"
samples/snippets/subscriber.py:546: error: Module "google.cloud.pubsub_v1.types" has no attribute "FieldMask"
samples/snippets/subscriber.py:571: error: Module has no attribute "Subscription"
samples/snippets/subscriber.py:843: error: On Python 3 '{}'.format(b'abc') produces "b'abc'", not 'abc'; use '{!r}'.format(b'abc') if this is desired behavior
samples/snippets/subscriber.py:915: error: On Python 3 '{}'.format(b'abc') produces "b'abc'", not 'abc'; use '{!r}'.format(b'abc') if this is desired behavior
samples/snippets/subscriber.py:922: error: On Python 3 '{}'.format(b'abc') produces "b'abc'", not 'abc'; use '{!r}'.format(b'abc') if this is desired behavior
Found 17 errors in 1 file (checked 1 source file)

@parthea
Copy link
Contributor

parthea commented Jan 11, 2024

cc @michaelpri10

@michaelpri10
Copy link
Contributor

cc @mukund-ananthu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/python-pubsub API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants