You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
Install google-cloud-pubsub, e.g. pipenv install --python 3.8 google-cloud-pubsub.
Run code below.
Code example
fromconcurrent.futuresimportTimeoutErrorfromtypingimportCallablefromgoogle.cloud.pubsub_v1importSubscriberClientfromgoogle.cloud.pubsub_v1.typesimportPubsubMessagedefprocess_messages(
project_id: str,
subscription_id: str,
callback: Callable[[PubsubMessage], None],
timeout: int=5,
) ->None:
subscriber=SubscriberClient()
subscription_path=subscriber.subscription_path(project_id, subscription_id)
streaming_pull_future=subscriber.subscribe(subscription_path, callback=callback)
withsubscriber:
try:
streaming_pull_future.result(timeout=timeout)
exceptTimeoutError:
streaming_pull_future.cancel() # Trigger the shutdown.streaming_pull_future.result() # Block until the shutdown is complete.if__name__=="__main__":
process_messages("my-project", "my-sub")
Stack trace
Traceback (most recent call last):
File "loaders.py", line 4, in <module>
from google.cloud.pubsub_v1 import SubscriberClient
File "/Users/tomphillips/.local/share/virtualenvs/loaders-emkxO8nx/lib/python3.8/site-packages/google/cloud/pubsub_v1/__init__.py", line 19, in <module>
from google.cloud.pubsub_v1 import subscriber
File "/Users/tomphillips/.local/share/virtualenvs/loaders-emkxO8nx/lib/python3.8/site-packages/google/cloud/pubsub_v1/subscriber/__init__.py", line 17, in <module>
from google.cloud.pubsub_v1.subscriber.client import Client
File "/Users/tomphillips/.local/share/virtualenvs/loaders-emkxO8nx/lib/python3.8/site-packages/google/cloud/pubsub_v1/subscriber/client.py", line 26, in <module>
from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
File "/Users/tomphillips/.local/share/virtualenvs/loaders-emkxO8nx/lib/python3.8/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 35, in <module>
import google.cloud.pubsub_v1.subscriber.message
File "/Users/tomphillips/.local/share/virtualenvs/loaders-emkxO8nx/lib/python3.8/site-packages/google/cloud/pubsub_v1/subscriber/message.py", line 20, in <module>
import pytz
ModuleNotFoundError: No module named 'pytz'
@tomwphillips Interesting, thanks for reporting this.
The workaround should of course be to install pytz manually, but it would still be good to get to the bottom of this.
I tried reproducing this in a slightly different way:
$ python3.8 -m venv env/new-3.8
$ . env/new-3.8/bin/activate
$ pip install google-cloud-pubsub
$ pip show pytz
Name: pytz
Version: 2021.1
Summary: World timezone definitions, modern and historical
Home-page: http://pythonhosted.org/pytz
Author: Stuart Bishop
Author-email: stuart@stuartbishop.net
License: MIT
Location: /home/peter/workspace/python-pubsub/env/new-3.8/lib/python3.8/site-packages
Requires:
Required-by: google-api-core
Using the venv module to create a fresh virtual environment worked fine, the library was installed with all its dependencies, including pytz. Could this be a bug in pipenv? Which pipenv version did you use?
FWIW, I tried this on Ubuntu Linux, but perhaps something is different on macOS. Could you perhaps try reproducing the issue with python3.8 -m venv as well?
@tomwphillips Thanks for confirming that venv works for you, too, it indeed seems likely that it's something in pipenv. Have you perhaps reported the issue there yet?
Also, would using venv in your process represent a feasible workaround?
@tomwphillips Just mentioning if interested - it turned out this was caused because the library implicitly depended on pytz, which was pulled in by the google-api-core dependency. When the latter dropped pytz, it broke the Pub/Sub client and a few other client libraries as well.
This has now been fixed in the v2.7.1 release. The Python Pub/Sub client does not use pytz anymore, thus any workarounds related to that can now be removed as well.
Activity
plamut commentedon Aug 11, 2021
@tomwphillips Interesting, thanks for reporting this.
The workaround should of course be to install
pytzmanually, but it would still be good to get to the bottom of this.I tried reproducing this in a slightly different way:
Using the
venvmodule to create a fresh virtual environment worked fine, the library was installed with all its dependencies, includingpytz. Could this be a bug inpipenv? Whichpipenvversion did you use?FWIW, I tried this on Ubuntu Linux, but perhaps something is different on macOS. Could you perhaps try reproducing the issue with
python3.8 -m venvas well?Thanks!
tomwphillips commentedon Aug 11, 2021
@plamut I think you might be right that this is a
pipenvbug. I'm using version2021.5.29.Following your example, I installed
google-cloud-pubsubusingpipandpytzis installed.plamut commentedon Aug 12, 2021
@tomwphillips Thanks for confirming that
venvworks for you, too, it indeed seems likely that it's something inpipenv. Have you perhaps reported the issue there yet?Also, would using
venvin your process represent a feasible workaround?tomwphillips commentedon Aug 12, 2021
I'll report it to
pipenvand specifypytzas a dependency in myPipfileas a workaround. Thanks, @plamut.plamut commentedon Aug 13, 2021
@tomwphillips FYI, we got the same issue report elsewhere, and it seems that it's a bug in
pipdependency resolver.We will remove the transitive dependency
pytz(throughgoogle-api-core) in #472, the change should be visible in the next release.fix: remove dependency on pytz (#472)
plamut commentedon Aug 20, 2021
@tomwphillips Just mentioning if interested - it turned out this was caused because the library implicitly depended on
pytz, which was pulled in by thegoogle-api-coredependency. When the latter droppedpytz, it broke the Pub/Sub client and a few other client libraries as well.This has now been fixed in the v2.7.1 release. The Python Pub/Sub client does not use
pytzanymore, thus any workarounds related to that can now be removed as well.