Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from google.cloud import storage fails: ImportError: No module named google.cloud

I'm having issue with accessing Google Storage through Python 3.6.I'm installing with:

pip install --upgrade google-cloud-storage

Here's my Python script:

from google.cloud import storage

def main():
    client = storage.Client()
    bucket = client.get_bucket('my_bucket')
    blob1 = bucket.blob('my_file.json')
    blob1.upload_from_filename(filename='my_file.json')

if __name__ == "__main__":
    main()

pip show google-cloud-storage gives me following output:

Name: google-cloud-storage
Version: 1.6.0
Summary: Python Client for Google Cloud Storage
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google Cloud Platform
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python3.6/dist-packages
Requires: google-api-core, google-auth, google-cloud-core, requests, google-resumable-media

Any idea what's wrong here?

like image 607
zinyosrim Avatar asked Jan 03 '18 11:01

zinyosrim


People also ask

How do I fix ModuleNotFoundError No module named Google?

To solve the Python "ModuleNotFoundError: No module named 'google. cloud'" error, install the specific google cloud module that you are importing, e.g. pip install google-cloud-speech if importing speech or pip install google-cloud-storage if importing storage .


1 Answers

There is a chance you are installing it with one python version (E.g. python2) and running your code with another version (E.g. python3).

Try mentioning versions of pip and python in the command.

To be precise, use pip of the python version you wanna run the code with. Example:

python3.6 -m pip install --upgrade google-cloud-storage

There could be multiple versions of Python installed on your system and multiple versions of pip as well, the above will make sure you are using the correct version of both.

like image 129
Amit Yadav Avatar answered Sep 30 '22 03:09

Amit Yadav