简体   繁体   English

从 google.cloud 导入存储失败:ImportError: No module named google.cloud

[英]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:我在通过 Python 3.6 访问 Google Storage 时遇到问题。我正在安装:

pip install --upgrade google-cloud-storage

Here's my Python script:这是我的 Python 脚本:

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: pip show google-cloud-storage给了我以下输出:

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: googleapis-publisher@google.com
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?知道这里有什么问题吗?

There is a chance you are installing it with one python version (Eg python2 ) and running your code with another version (Eg python3 ).您有可能使用一个python版本(例如python2 )安装它并使用另一个版本(例如python3 )运行您的代码。

Try mentioning versions of pip and python in the command.尝试在命令中提及pippython版本。

To be precise, use pip of the python version you wanna run the code with.准确地说,使用你想要运行代码的 python 版本的 pip。 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 .有可能是Python的多个版本的系统和多个版本上安装pip还有,上面会确保你同时使用的正确版本。

我遇到了同样的问题并通过以管理员身份运行我的脚本来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自google.cloud导入firestore ModuleNotFoundError:没有名为'google'的模块 - from google.cloud import firestore ModuleNotFoundError: No module named 'google' ImportError 无法从“google.cloud”(未知位置)导入“langauge” - ImportError cannot import 'langauge' from 'google.cloud' (unknown location) Apache Beam Jupyter Notebook:ImportError: cannot import name 'storage' from 'google.cloud'(未知位置) - Apache Beam Jupyter Notebook: ImportError: cannot import name 'storage' from 'google.cloud' (unknown location) ModuleNotFoundError:没有名为“google.cloud”的模块,即使我安装了它 - ModuleNotFoundError: No module named 'google.cloud' even though I installed it 无法在 python 脚本中使用 google.cloud(存储) - Unable to use google.cloud (storage) from within a python script google.cloud storage python api在指定位置创建存储桶 - google.cloud storage python api create bucket in specified location __init__.py 中的 google.cloud 命名空间导入错误 - google.cloud namespace import error in __init__.py google.cloud在哪个python库中? - In what python library is google.cloud? 无法从“google.cloud”(未知位置)导入名称“dataproc_v1” - cannot import name 'dataproc_v1' from 'google.cloud' (unknown location) 使用google.cloud获取BigQuery表架构 - Get BigQuery table schema using google.cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM