Closed goern closed 5 years ago
Trying to reproduce by installing google-cloud-pubsub==0.38.0
in a fresh virtual environment:
$ python3.6 -m venv /tmp/gcp/6531
$ /tmp/gcp/6531/bin/pip install --upgrade setuptools pip wheel
...
Successfully installed cachetools-3.0.0 certifi-2018.10.15 chardet-3.0.4 google-api-core-1.5.2 google-auth-1.6.1 google-cloud-pubsub-0.38.0 googleapis-common-protos-1.5.5 grpc-google-iam-v1-0.11.4 grpcio-1.16.1 idna-2.7 protobuf-3.6.1 pyasn1-0.4.4 pyasn1-modules-0.2.2 pytz-2018.7 requests-2.20.1 rsa-4.0 six-1.11.0 urllib3-1.24.1
$ /tmp/gcp/6531/bin/pip freeze
-f file:///...
cachetools==3.0.0
certifi==2018.10.15
chardet==3.0.4
google-api-core==1.5.2
google-auth==1.6.1
google-cloud-pubsub==0.38.0
googleapis-common-protos==1.5.5
grpc-google-iam-v1==0.11.4
grpcio==1.16.1
idna==2.7
protobuf==3.6.1
pyasn1==0.4.4
pyasn1-modules==0.2.2
pytz==2018.7
requests==2.20.1
rsa==4.0
six==1.11.0
urllib3==1.24.1
$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json"
$ /tmp/gcp/6531/bin/python
Python 3.6.7 (default, Oct 22 2018, 11:30:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.cloud import pubsub
>>> client = pubsub.SubscriberClient()
>>> import google.iam.v1.iam_policy_pb2
>>> google.iam.v1.iam_policy_pb2.IAMPolicyStub
<class 'google.iam.v1.iam_policy_pb2.IAMPolicyStub'>
Can you check the actually-installed version of grpc-google-iam-v1
, and that the imported file is the one you expect? E.g. via:
>>> import pkg_resources
>>> pkg_resources.get_distribution('grpc-google-iam-v1').version
'0.11.4'
>>> import google.iam.v1.iam_policy_pb2
>>> google.iam.v1.iam_policy_pb2.__file__
'/tmp/gcp/6531/lib/python3.6/site-packages/google/iam/v1/iam_policy_pb2.py'
@goern Please feel free to reopen the issue if you can provide the information needed.
I have the issue with the python37 environment in google cloud app. The installed version is the correct one according to pkg_resources, but google.iam.v1.iam_policy_pb2.IAMPolicyStub
is not there.
import google.iam.v1.iam_policy_pb2
import pkg_resources
print(google.iam.v1.iam_policy_pb2.__file__)
print(pkg_resources.get_distribution('grpc-google-iam-v1'))
produces:
2018-12-13 15:34:08 default[--] /env/lib/python3.7/site-packages/google/iam/v1/iam_policy_pb2.py
2018-12-13 15:34:08 default[--] grpc-google-iam-v1 0.11.4
@julian-r How are you installing the packages? I just tried installing only grcp-google-iam-v1==0.11.4
:
$ python3.7 -m venv /tmp/gcp/6531
$ /tmp/gcp/6531/bin/pip install --upgrade setuptools pip wheel
...
Successfully installed pip-18.1 setuptools-40.6.3 wheel-0.32.3
$ /tmp/gcp/6531/bin/pip install grpc-google-iam-v1==0.11.4
...
Successfully installed googleapis-common-protos-1.5.5 grpc-google-iam-v1-0.11.4 grpcio-1.17.0 protobuf-3.6.1 six-1.12.0
$ /tmp/gcp/6531/bin/pip freeze
-f file:///.../.pip/wheels
googleapis-common-protos==1.5.5
grpc-google-iam-v1==0.11.4
grpcio==1.17.0
protobuf==3.6.1
six==1.12.0
$ /tmp/gcp/6531/bin/python
Python 3.7.1 (default, Oct 22 2018, 11:31:38)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.iam.v1 import iam_policy_pb2
>>> iam_policy_pb2.IAMPolicyStub
<class 'google.iam.v1.iam_policy_pb2.IAMPolicyStub'>
Fun fact: it works on my desktop environment, but in app engine it can't find the class. Locally I am using pipenv. I generate a requirements.txt
with pipenv freeze --requirements
and app engine installs them.
Now I also tried to check if the imports of iam_policy_pb2.py:300
are working
# THESE ELEMENTS WILL BE DEPRECATED.
# Please use the generated *_pb2_grpc.py files instead.
import grpc
from grpc.beta import implementations as beta_implementations
from grpc.beta import interfaces as beta_interfaces
from grpc.framework.common import cardinality
from grpc.framework.interfaces.face import utilities as face_utilities
which seems to be fine.
My versions in the requirements.txt
:
google-api-core[grpc]==1.6.0
google-auth==1.6.1
google-cloud-core==0.29.0
google-cloud-pubsub==0.39.0
google-cloud-storage==1.13.1
google-resumable-media==0.3.1
googleapis-common-protos[grpc]==1.5.5
grpc-google-iam-v1==0.11.4
grpcio==1.17.0
...
protobuf==3.6.1
do exactly match yours.
@julian-r have you fixed the issue? I am having the same problem.
My versions are slightly newer than yours and @tseaver. (I've also tried downgrading to match)
Pipfile: Pipfile.txt
$ pip freeze
appdirs==1.4.3
appnope==0.1.0
astroid==2.1.0
attrs==18.2.0
backcall==0.1.0
black==18.9b0
cachetools==3.0.0
certifi==2018.11.29
chardet==3.0.4
Click==7.0
decorator==4.3.0
google-api-core==1.7.0
google-auth==1.6.2
google-cloud-pubsub==0.39.1
googleapis-common-protos==1.6.0b6
grpc-google-iam-v1==0.11.4
grpcio==1.17.1
idna==2.8
ipython==7.2.0
ipython-genutils==0.2.0
isort==4.3.4
jedi==0.13.2
lazy-object-proxy==1.3.1
mccabe==0.6.1
neo4j-driver==1.7.1
neobolt==1.7.3
neotime==1.7.4
parso==0.3.1
pexpect==4.6.0
pickleshare==0.7.5
prompt-toolkit==2.0.7
protobuf==3.6.1
ptyprocess==0.6.0
pyasn1==0.4.5
pyasn1-modules==0.2.3
Pygments==2.3.1
pylint==2.2.2
python-decouple==3.1
pytz==2018.7
requests==2.21.0
rsa==4.0
six==1.12.0
toml==0.10.0
traitlets==4.3.2
urllib3==1.24.1
wcwidth==0.1.7
wrapt==1.10.11
And my code (followed from https://github.com/googleapis/google-cloud-python/tree/master/pubsub#subscribing)
project_id = config("PROJECT_ID")
topic_name = config("TOPIC_NAME")
publisher = pubsub_v1.PublisherClient()
topic_name = "projects/{project_id}/topics/{topic_name}"
publisher.create_topic(topic_name)
Stacktrace when running:
~/Projects/platform/collectors/platform-collector/keystoneworks/app.py in <module>
16
17
---> 18 publisher = pubsub_v1.PublisherClient()
19 topic_name = "projects/{project_id}/topics/{topic_name}"
20 publisher.create_topic(topic_name)
~/.local/share/virtualenvs/platform-collector-Dej9gSN_/lib/python3.7/site-packages/google/cloud/pubsub_v1/publisher/client.py in __init__(self, batch_settings, **kwargs)
87 # Add the metrics headers, and instantiate the underlying GAPIC
88 # client.
---> 89 self.api = publisher_client.PublisherClient(**kwargs)
90 self.batch_settings = types.BatchSettings(*batch_settings)
91
~/.local/share/virtualenvs/platform-collector-Dej9gSN_/lib/python3.7/site-packages/google/cloud/pubsub_v1/gapic/publisher_client.py in __init__(self, transport, channel, credentials, client_config, client_info)
169 else:
170 self.transport = publisher_grpc_transport.PublisherGrpcTransport(
--> 171 address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
172 )
173
~/.local/share/virtualenvs/platform-collector-Dej9gSN_/lib/python3.7/site-packages/google/cloud/pubsub_v1/gapic/transports/publisher_grpc_transport.py in__init__(self, channel, credentials, address)
69 # channel and provide a basic method for each RPC.
70 self._stubs = {
---> 71 "iam_policy_stub": iam_policy_pb2.IAMPolicyStub(channel),
72 "publisher_stub": pubsub_pb2_grpc.PublisherStub(channel),
73 }
AttributeError: module 'google.iam.v1.iam_policy_pb2' has no attribute 'IAMPolicyStub'
Stracktrace when importing in the shell:
In [2]: from google.iam.v1 import iam_policy_pb2
In [3]: iam_policy_pb2.IAMPolicyStub
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-08df3e5719b4> in <module>
----> 1 iam_policy_pb2.IAMPolicyStub
AttributeError: module 'google.iam.v1.iam_policy_pb2' has no attribute 'IAMPolicyStub'
Any ideas?
Thanks!
I got it to work. What I had to do.
Removed black (so I could remove allow_prereleases = true
) Then I destroyed the venv and recreated. (Doining an uninstall of black and pipenv clean
, didn't work)
Thoughts on why:
Allowing prereleases installed googleapis-common-protos==1.6.0b6
.
I had the same problem. @ambv please release a stable version of black :pray:
Please run down the following list and make sure you've tried the usual "quick fixes":
Environment details
pip show google-<service>
orpip freeze
Steps to reproduce
git clone github.com:goern/sesheta-google-chatbot.git .
pipenv install
pipenv shell ./app.py
Code example
Stack trace
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!