我想测试一些与我今天在本地运行的 GCS 交互的代码。我的计划是:
- 在 GDrive 中保存服务帐户 JSON 文件
- 将其下载到 Colaboratory 的“本地”/tmp
!export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>
storage_client = storage.Client('my-project')
并使用不同的方法/属性。
我安装了!pip install --upgrade google-cloud
,但是在测试第 4 项(预计会出现身份验证错误)时,我收到一条消息重新依赖问题:
ContextualVersionConflictTraceback (most recent call last)
<ipython-input-13-7346ac058842> in <module>()
----> 1 from google.cloud import storage
2
3
4 # Authenticate to GCS.
5 from google.colab import auth
/usr/local/lib/python2.7/dist-packages/google/cloud/storage/__init__.py in <module>()
33
34 from pkg_resources import get_distribution
---> 35 __version__ = get_distribution('google-cloud-storage').version
36
37 from google.cloud.storage.batch import Batch
/usr/lib/python2.7/dist-packages/pkg_resources/__init__.pyc in get_distribution(dist)
554 dist = Requirement.parse(dist)
555 if isinstance(dist, Requirement):
--> 556 dist = get_provider(dist)
557 if not isinstance(dist, Distribution):
558 raise TypeError("Expected string, Requirement, or Distribution", dist)
/usr/lib/python2.7/dist-packages/pkg_resources/__init__.pyc in get_provider(moduleOrReq)
428 """Return an IResourceProvider for the named module or requirement"""
429 if isinstance(moduleOrReq, Requirement):
--> 430 return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
431 try:
432 module = sys.modules[moduleOrReq]
/usr/lib/python2.7/dist-packages/pkg_resources/__init__.pyc in require(self, *requirements)
970 included, even if they were already activated in this working set.
971 """
--> 972 needed = self.resolve(parse_requirements(requirements))
973
974 for dist in needed:
/usr/lib/python2.7/dist-packages/pkg_resources/__init__.pyc in resolve(self, requirements, env, installer, replace_conflicting, extras)
861 # Oops, the "best" so far conflicts with a dependency
862 dependent_req = required_by[req]
--> 863 raise VersionConflict(dist, req).with_context(dependent_req)
864
865 # push the new requirements onto the stack
ContextualVersionConflict: (google-cloud-core 0.27.1 (/usr/local/lib/python2.7/dist-packages), Requirement.parse('google-cloud-core<0.29dev,>=0.28.0'), set(['google-cloud-storage']))
我没有在 Datalab 中尝试过,但 Colaboratory 更方便。