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 }}
Repository navigation
Can't import google.protobuf.timestamp_pb2 from App Engine #1436
I'm getting ImportError: No module named protobuf from the line from google.protobuf import timestamp_pb2 because the google module refers to the AppEngine SDK.
This is a well-known issue that's been around for years. Maybe you can bundle protobuf directly inside gcloud-python instead of an external dependency?
How do you vendor in gcloud-python for App Engine?
Do you vendor in protobuf? (AFAIK it isn't part of the GAE runtime)
Which services / gcloud-python subpackages do you use? (I'm curious which imports / import paths your code has been using.)
Are you modify the gcloud module object so that it acts like a namespace package? If no, this is the solution to your problem. I made an app that shows how to do this. The app is now out-of-date but the file that handles protobuf imports is still valid.
Are you modify the gcloud module object so that it acts like a namespace package? If no, this is the solution to your problem. I made an app that shows how to do this. The app is now out-of-date but the file that handles protobuf imports is still valid.
I don't think this shouldn't be necessary anymore, I'm interested to see if that's somehow changed.
Do you vendor in protobuf? (AFAIK it isn't part of the GAE runtime)
It's in libs, so yes.
Which services / gcloud-python subpackages do you use? (I'm curious which imports / import paths your code has been using.)
from gcloud import storage
File "/x/libs/gcloud/storage/__init__.py", line 43, in <module>
from gcloud.storage.blob import Blob
File "/x/libs/gcloud/storage/blob.py", line 27, in <module>
from gcloud._helpers import _rfc3339_to_datetime
File "/x/libs/gcloud/_helpers.py", line 26, in <module>
from google.protobuf import timestamp_pb2
ImportError: No module named protobuf
@kvdb Thanks a lot. I'm wondering now if it may be related to Darth-Vendor and namespace packages not being the best of friends. I need to dig in and reproduce. Can you confirm that's what you used to vendor in your package?
Darth is part of the SDK (from google.appengine.ext import vendor) so that's definitely what's being used. It explicitly has support for namespaces. So I'm also unsure what's going on.
@tseaver, @jonparrott installing it with pip put the package in the wrong directory.
And appengine expects it in its own directory google_appengine/google.
Traceback (most recent call last):
File "./src/main.py", line 9, in <module>
from google.cloud import logging, pubsub
File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/__init__.py", line 18, in <module>
from google.cloud.logging.client import Client
File "/usr/local/lib/python2.7/dist-packages/google/cloud/logging/client.py", line 32, in <module>
from google.cloud.client import JSONClient
File "/usr/local/lib/python2.7/dist-packages/google/cloud/client.py", line 21, in <module>
from google.cloud._helpers import _determine_default_project
File "/usr/local/lib/python2.7/dist-packages/google/cloud/_helpers.py", line 30, in <module>
from google.protobuf import timestamp_pb2
ImportError: cannot import name timestamp_pb2
@ensonic Run import google; print(google.__path__) so see what the problem is. The usual suspect here is that you have a "bad" package breaking the google namespace. (The fact that you have the very old gcloud co-tenant with google-cloud isn't a good sign.)
Neither need be gotten rid of AFAIK. From there you'd want to poke around in /usr/local/lib/python2.7/dist-packages/google/__init__.py and see if it is a namespace package or otherwise (you also need to look around for (maybe bad?) .nspkg files in your site-packages
Activity
dhermes commentedon Feb 1, 2016
Thanks for reporting and for upgrading!
I am curious about a few things:
gcloud-pythonfor App Engine?protobuf? (AFAIK it isn't part of the GAE runtime)gcloud-pythonsubpackages do you use? (I'm curious which imports / import paths your code has been using.)gcloudmodule object so that it acts like a namespace package? If no, this is the solution to your problem. I made an app that shows how to do this. The app is now out-of-date but the file that handlesprotobufimports is still valid.theacodes commentedon Feb 1, 2016
I don't think this shouldn't be necessary anymore, I'm interested to see if that's somehow changed.
dhermes commentedon Feb 1, 2016
Me too. Thanks for chiming in @jonparrott I was going to ping you.
theacodes commentedon Feb 1, 2016
I should really write an App Engine test case.
dhermes commentedon Feb 9, 2016
@SaMnCo also reported this import error, it may be
pipdoesn't upgrade deps insetup.pyas I expectPYTHONPATHissuedhermes commentedon Feb 11, 2016
@SaMnCo can you do a
pip show protobuf,pip show gcloudin the environment where this is failing and then make sure the same versions are imported:kvdb commentedon Feb 18, 2016
@dhermes I think I've got a similar problem as the reporter of the issue. Perhaps I can help by providing my answers to your questions:
In
appengine_config.py:Results in:
It's in
libs, so yes.dhermes commentedon Feb 18, 2016
@kvdb Thanks a lot. I'm wondering now if it may be related to Darth-Vendor and namespace packages not being the best of friends. I need to dig in and reproduce. Can you confirm that's what you used to vendor in your package?
theacodes commentedon Feb 18, 2016
Darth is part of the SDK (
from google.appengine.ext import vendor) so that's definitely what's being used. It explicitly has support for namespaces. So I'm also unsure what's going on.dhermes commentedon Feb 19, 2016
Maybe it's an issue with old versions of
pip? The module certainly shows up:Going to run a test app in
dev_appserverto verify import works.dhermes commentedon Feb 19, 2016
OK I just confirmed this works in
dev_appserveras well.@kvdb Have you tried clearing out
liband starting fresh? What version ofpipare you using?[-]AppEngine support broken in 0.9.0[/-][+]Can't import google.protobuf.timestamp_pb2 from App Engine[/+]kvdb commentedon Feb 21, 2016
pip 8.0.2
Yes, I cleared my virtualenv/libs before reporting.
dhermes commentedon Feb 21, 2016
Very strange! Does the
timestamp_pb2.pyfile exist and just the import fails or the file never shows up?62 remaining items
yanik-ai commentedon Sep 5, 2016
@tseaver, @jonparrott installing it with pip put the package in the wrong directory.
And appengine expects it in its own directory
google_appengine/google.theacodes commentedon Sep 6, 2016
@yanikkoval can you give us more details? What exact pip command are you running? What's in your
appengine_config.py?ensonic commentedon Feb 21, 2017
It is also happening on local machine using Ubuntu 14.04 LTS - from pip freze:
dhermes commentedon Feb 21, 2017
@ensonic Run
import google; print(google.__path__)so see what the problem is. The usual suspect here is that you have a "bad" package breaking thegooglenamespace. (The fact that you have the very oldgcloudco-tenant withgoogle-cloudisn't a good sign.)ensonic commentedon Feb 21, 2017
@dhermes
which ones should I get rid of - the 'grpc-google-' or 'gapic-google-'
dhermes commentedon Feb 21, 2017
Neither need be gotten rid of AFAIK. From there you'd want to poke around in
/usr/local/lib/python2.7/dist-packages/google/__init__.pyand see if it is a namespace package or otherwise (you also need to look around for (maybe bad?).nspkgfiles in your site-packagesSpeech API: enhanced model and recognition metadata [(#1436)](GoogleC…
Speech API: enhanced model and recognition metadata [(#1436)](GoogleC…
Speech API: enhanced model and recognition metadata [(#1436)](GoogleC…
Speech API: enhanced model and recognition metadata [(#1436)](GoogleC…
fix(rest): Use strict encoding to lowercase query string bools (#1436)
fix: fix user cred universe domain issue (#1436)
docs: created samples for load table and create table from schema file (
feat: Support dry_run in `to_pandas()` (#1436)
docs: migrate code from googleapis/python-bigquery (#18303)