我是Google Cloud平台的新手,在DataLab的Jupyter notebook上上传了一些机器学习代码。
我的问题是,虽然我安装了Google Cloud Storage (使用命令:pip install --upgrade google-cloud-storage
),但我无法导入它。
下面是我导入这个包的方法:
>>import numpy
>>import pandas as pd
>>from google.cloud import storage
但是我得到了以下错误:
()中的
ImportErrorTraceback (最近一次调用)->1来自google.cloud导入存储
ImportError:无法导入名称存储
注意:
shell
{"TokenSources":["env"]}
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json"
:中键入pip freeze来验证此软件包确实安装在我的环境中
google-cloud==0.34.0
google-cloud-datastore==1.7.0
google-cloud-spanner==1.4.0
google-cloud-storage==1.10.0
这里我漏掉了什么?
发布于 2018-08-30 03:58:21
您是否在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/。
发布于 2018-08-31 07:54:49
因此,我让它在导入存储时工作,如下所示:
将google.datalab.storage作为存储
导入
发布于 2019-07-08 12:33:26
要使您的笔记本能够同时适应datalab和非datalab环境,您可以使用以下方法之一来处理导入语句:
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
错误
https://stackoverflow.com/questions/52084665
复制相似问题