2017-12-02 26 views
0

오늘 제가 로컬로 실행중인 GCS와 상호 작용하는 코드를 테스트하고 싶었습니다.구글 클라우드 libs가 Colaboratory에서 작동하지 않습니다.

  1. 이 Colaboratory의 '지역'/ tmp를
  2. !export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>
  3. storage_client = storage.Client('my-project')
  4. 다운로드에게 G 드라이브에이를 서비스 계정 JSON 파일을 저장하고 다른 방법/속성 재생 : 내 계획이다.

나는 !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이 훨씬 더 편리합니다.

답변

1

그래서 여기에 두 가지 문제/질문이 있습니다 :

  1. 내가 서비스 계정 자격 증명을 사용할 수 있습니까? 나는 다만 일이 잘 될 것이라고 생각하지만, 먼저 뭔가 다른 것으로 넘어지고 있습니다.

  2. google.cloud.storage을 가져 오는 중 오류가 발생합니까? 여기에 문제는 다음과 같습니다. 시작시 google.cloud 라이브러리의 일부 하위 세트를로드합니다. 그런 다음 업그레이드를 수행하고 이미로드 된 라이브러리와 충돌하는 새로 설치된 라이브러리를로드하려고 시도합니다.

    가장 빠른 수정되는 점 일들이 잘로드해야합니다, 단지 설치 (ctrl-m .) 후 커널을 다시 시작하는 것입니다.

+0

하위 집합 로딩이 모든 것을 설명 : 나는 구글에서 ''수입 google.cloud'을하지만 수 없었다. 클라우드 가져 오기 저장소'. 따라서 최신 정보를 얻으려는 생각. 시작시 해결 방법 접수 및 테스트하지만, 전체 패키지는 참으로 가장 좋은 것입니다 –

0

서비스 계정이 필요합니까? I/O example notebook for GCS에 표시된 조리법을 사용하여 Colab에서 직접 개인 자격 증명을 사용할 수 있습니다.

Colab VM은 공유되지 않으므로 프로젝트에서 공유되는 GCE VM의 사용자 자격 증명에 대한 일반적인주의 사항은 적용되지 않습니다.

GCS 스토리지 Python API에 서비스 계정을 사용해야하는 경우 알려 주시면 예제를 작성하겠습니다.

+0

감사합니다. 구문을 다시 보았습니다. 너무 많은 추상화 레이어 : GAE는 GCE/GKE 다른 또는 이전 REST API를 JSON 또는 XML, 또는 새로운 Google 클라우드 클라이언트 libs와 [여기]와 '지역'있는, Colab 지금, 그것의 자신의 (https : //로 googlecloudplatform .github.io/google-cloud-python/stable/storage/blobs.html). 내 기존 코드는 후자에 따라 서비스 계정이 왜 필요합니다. 아이디어는 Colab을 사용하여 팀의 기능 및 문서 결과를 신속하게 시험해 보는 것이 었습니다. 흥미롭게 내가 MSFT 또는 AWS 노트북에서 액세스 및 사용할 경우 나는 어떤 문제/의존성 오류가 없을 것입니다 내기 ... –