googleapis / google-cloud-python

Google Cloud Client Library for Python
https://googleapis.github.io/google-cloud-python/
Apache License 2.0
4.83k stars 1.53k forks source link

Storage/Firestore: (in Cloud Functions): Dependencies need a specific sequence #6131

Closed StefMa closed 6 years ago

StefMa commented 6 years ago
  1. Specify the API at the beginning of the title (for example, "BigQuery: ...") General, Core, and Other are also allowed as types ✅
  2. OS type and version I use both in Cloud Functions (Beta Runtime)
  3. Python version and virtual environment information python --version 3.7
  4. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
  5. Stacktrace if available
    Stacktrace
Detailed stack trace: Traceback (most recent call last):
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/worker.py", line 211, in check_or_load_user_function
    _function_handler.load_user_function()
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/worker.py", line 140, in load_user_function
    spec.loader.exec_module(main)
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/user_code/main.py", line 2, in <module>

    from google.cloud import firestore
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore.py", line 18, in <module>
    from google.cloud.firestore_v1beta1 import __version__
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/__init__.py", line 21, in <module>
    from google.cloud.firestore_v1beta1._helpers import GeoPoint
  File "/env/local/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/_helpers.py", line 24, in <module>
    import grpc
ModuleNotFoundError: No module named 'grpc'

  1. Steps to reproduce Add this to your requirements.txt:
    google-cloud-storage==1.12.0
    google-cloud-firestore==0.29.0

    And import both in the main.py:

    from google.cloud import storage
    from google.cloud import firestore

    Then deploy the function...

  2. Code example ☝️ See above

When I change the requirements.txt to:

from google.cloud import firestore
from google.cloud import storage

So basically switching the dependencies - it works without any issue.

I don't know if that have something to do that firestore is not "offical" supported for 3.7 as the README says currently or something different 🤷‍♂️ (Maybe its also a issue on the Cloud Function side. Then it would be great to ping me where I can report this issue 👍 ) bildschirmfoto 2018-09-28 um 10 38 41 But because I'm not that Python expert I wanted to report this 😇

tseaver commented 6 years ago

@StefMa Thanks for the report! This issue is actually a bug in pip, such that it does not enforce "extras" for a package it has already installed. The workaround you found (installing google-cloud-firestore, which depends on the grpc extra of google-api_core) before google-cloud-storage, which does not, is all we can do for now.