google.cloud import storage: cannot import storage

后端 未结 3 1810
忘了有多久
忘了有多久 2020-12-17 10:00

I tried to run the code bellow by following the google tutorials i found here: https://cloud.google.com/docs/authentication/production

def implicit():
    fr         


        
相关标签:
3条回答
  • 2020-12-17 10:08

    Also, make sure your main.py file and the requirements.txt are in the same directory and the same directory as the function being deployed.

    Just FYI, because I had to do this even after specifying my environment variables.

    0 讨论(0)
  • 2020-12-17 10:14

    I got the error cause i forgot to specify it in "requirements.txt"

    0 讨论(0)
  • 2020-12-17 10:30

    I see you are trying to use the Google Cloud Storage client libraries.

    In order to use it, you should first make sure that it is installed in your machine:

    pip install --upgrade google-cloud-storage
    

    And then, you should probably set up authentication (if you are using Application Default Credentials, from the documentation you mentioned), by setting up the GOOGLE_APPLICATION_CREDENTIALS environment variable in the machine where you are running the code, like below. If you are using Windows, follow the steps presented in the documentation, instead.

    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json"
    

    Alternatively, you can try using explicit credentials. The only difference between the one you shared (using implicit credentials obtained from the environment) and one using explicit credentials, is that when you declare the GCS client, you should do something like:

    storage_client = storage.Client.from_service_account_json('/path/to/SA_key.json')
    

    Once all this is ready, you should have no issues with running the sample code you provided. In order to keep learning about GCS and its client libraries, feel free to search on the documentation I linked and have a look at the library reference page.

    0 讨论(0)
提交回复
热议问题