简体   繁体   English

无法从google.cloud导入存储空间

[英]Unable to import storage from google.cloud

I'm new to Google Cloud Platform, and have uploaded some machine learning code on Jupyter notebook in DataLab. 我是Google Cloud Platform的新手,并在DataLab中的Jupyter笔记本上上传了一些机器学习代码。

My issue is although, I installed Google Cloud Storage (using the command: pip install --upgrade google-cloud-storage ), I'm unable to import this. 我的问题是,虽然我安装了Google云端存储(使用命令: pip install --upgrade google-cloud-storage ),但我无法导入。

The following is how I'm importing this package: 以下是我导入此包的方式:

>>import numpy    
>>import pandas as pd   
>>from google.cloud import storage

But I'm getting the following error: 但是我收到以下错误:

ImportErrorTraceback (most recent call last) in () ----> 1 from google.cloud import storage 从google.cloud导入存储中的()----> 1中的ImportErrorTraceback(最近一次调用最后一次)

ImportError: cannot import name storage ImportError:无法导入名称存储

Note: 注意:

  1. This is the content of my JSON config file: {"TokenSources":["env"]} 这是我的JSON配置文件的内容: {"TokenSources":["env"]}
  2. I tried export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json" , but the error persists. 我尝试export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json" ,但错误仍然存​​在。
  3. I verified that this package is indeed installed in my environment by typing pip freeze in the command shell: 我通过在命令shell中键入pip freeze来验证此包确实安装在我的环境中:

google-cloud==0.34.0 谷歌云== 0.34.0

google-cloud-datastore==1.7.0 谷歌云的数据存储== 1.7.0

google-cloud-spanner==1.4.0 谷歌云,扳手== 1.4.0

google-cloud-storage==1.10.0 谷歌云存储== 1.10.0


What am I missing here? 我在这里错过了什么?

So I got it working upon importing storage as follows: 所以我按照以下方式导入存储:

import google.datalab.storage as storage 将google.datalab.storage导入为存储

To make your notebooks resilient to both datalab and non-datalab environments you can use one of the the following methods for handling your import statements: 要使您的笔记本对datalab和非datalab环境都具有弹性,您可以使用以下方法之一来处理import语句:

try:
  from google.cloud import storage
except ImportError:
  from google.datalab import storage

or 要么

if 'google.datalab' in sys.modules:
  from google.datalab import storage
else:
  from google.cloud import storage

Alternatively if you would like to switch datalab to using from google.cloud import storage 或者,如果您想将datalab切换为使用from google.cloud import storage

Run the following in a cell 在单元格中运行以下命令

!pip install google-cloud-storage

Followed by this cell to reset the IPython kernel 接下来是这个单元格来重置IPython内核

# Reset the IPython kernel
from IPython.core.display import HTML
HTML("<script>Jupyter.notebook.kernel.restart()</script>")

Note : You need to reset the Python kernel after installation otherwise you will a ContextualVersionConflict error from naming conflicts 注意 :您需要在安装后重置Python内核,否则您将在命名冲突时出现ContextualVersionConflict错误

Have you installed the google-cloud-storage package in your DataLab environment, or on your local machine? 您是否在DataLab环境或本地计算机上安装了google-cloud-storage软件包? You'll need to run the following command within DataLab: 您需要在DataLab中运行以下命令:

!pip install google-cloud-storage

See https://cloud.google.com/datalab/docs/how-to/adding-libraries for more details 有关详情,请参阅https://cloud.google.com/datalab/docs/how-to/adding-libraries

Also, the google-cloud package is deprecated, you shouldn't need to install it, see https://pypi.org/project/google-cloud/ . 此外,不推荐使用google-cloud软件包,您无需安装它,请参阅https://pypi.org/project/google-cloud/

暂无
暂无

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

相关问题 无法导入“从 google.cloud 导入 bigquery” - unable to import "from google.cloud import bigquery" 无法在 python 脚本中使用 google.cloud(存储) - Unable to use google.cloud (storage) from within a python script google.cloud 导入存储:无法导入存储 - google.cloud import storage: cannot import storage Cloud Function 无法从“google.cloud”(未知位置)导入名称“storage” - Cloud Function cannot import name 'storage' from 'google.cloud' (unknown location) 对于 Python,“import gcsfs”或“from google.cloud import storage”与 GCS 交互 - For Python, “import gcsfs” or “from google.cloud import storage” to interact with GCS 导入错误:无法从“google.cloud”(未知位置)导入名称“bigquery_storage_v1beta1” - ImportError: cannot import name 'bigquery_storage_v1beta1' from 'google.cloud' (unknown location) 来自google.cloud导入语言ModuleNotFoundError:没有名为“ google.cloud”的模块 - from google.cloud import language ModuleNotFoundError: No module named 'google.cloud' 来自google.cloud导入firestore ModuleNotFoundError:没有名为&#39;google&#39;的模块 - from google.cloud import firestore ModuleNotFoundError: No module named 'google' 从google.cloud导入bigquery ModuleNotFoundError:没有名为“ google”的模块 - from google.cloud import bigquery ModuleNotFoundError: No module named 'google' 无法从google.cloud导入数据存储 - Can't import Datastore from google.cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM