google.cloud import storage: cannot import storage

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.


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.


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