繁体   English   中英

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

[英]Unable to import storage from google.cloud

我是Google Cloud Platform的新手,并在DataLab中的Jupyter笔记本上上传了一些机器学习代码。

我的问题是,虽然我安装了Google云端存储(使用命令: pip install --upgrade google-cloud-storage ),但我无法导入。

以下是我导入此包的方式:

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

但是我收到以下错误:

从google.cloud导入存储中的()----> 1中的ImportErrorTraceback(最近一次调用最后一次)

ImportError:无法导入名称存储

注意:

  1. 这是我的JSON配置文件的内容: {"TokenSources":["env"]}
  2. 我尝试export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json" ,但错误仍然存​​在。
  3. 我通过在命令shell中键入pip freeze来验证此包确实安装在我的环境中:

谷歌云== 0.34.0

谷歌云的数据存储== 1.7.0

谷歌云,扳手== 1.4.0

谷歌云存储== 1.10.0


我在这里错过了什么?

所以我按照以下方式导入存储:

将google.datalab.storage导入为存储

要使您的笔记本对datalab和非datalab环境都具有弹性,您可以使用以下方法之一来处理import语句:

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

要么

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

或者,如果您想将datalab切换为使用from google.cloud import storage

在单元格中运行以下命令

!pip install google-cloud-storage

接下来是这个单元格来重置IPython内核

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

注意 :您需要在安装后重置Python内核,否则您将在命名冲突时出现ContextualVersionConflict错误

您是否在DataLab环境或本地计算机上安装了google-cloud-storage软件包? 您需要在DataLab中运行以下命令:

!pip install google-cloud-storage

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

此外,不推荐使用google-cloud软件包,您无需安装它,请参阅https://pypi.org/project/google-cloud/

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM