LoginSignup
1
4

More than 5 years have passed since last update.

ubuntuでgcpを使えるようになるまでの最短ルート(python)

Last updated at Posted at 2017-11-01

はじめに

Debian / Ubuntu 用のクイックスタート
に添って説明していく。(2017/10/30のバージョン)
この記事を書いている段階ではpython3系に対してないっぽいので、python2.7.13でやっています。

gcpのアカウントを作成

スクショを撮り忘れてしまったので略

Google Cloud SDK のインストール

bashrcに以下のものを追加

export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"

以下の3つのコマンドを実行

echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install google-cloud-sdk

このときProblem executing scripts APT...みたいなエラーを吐かれたらここにかかれているコマンドを実行。

初期設定

上のページのSDKの初期化に添って行う
Compute Engineは「asia-northeast1-a」を選択すれば良い。ちなみに「asia-northeast1-*」は東京にあるサーバー

これで、gcpの認証については終了。次はpythonのmoduleのインストールに移る。

pythonの環境設定(speech apiとnatural language apiについてのみ)

はじめに

上記のsdkは2系のpythonでしか動かないが、プログラムは3系でも動く。謎。

speech api

サンプルコードはここ
https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/speech/cloud-client

環境構築

git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

でgitをclone。 その後、上記のURLに当たるディレクトリ部分まで移動し、以下のコマンドを実行

pip install -r requirements.txt

動作確認

python transcribe.py resources/audio.raw

蛇足だが、個人的には下のソースコードの方がわかりやすいので、自分でプログラムを組むときはこっちを参考に作った方がよさげ
https://cloud.google.com/speech/docs/reference/libraries?hl=ja#client-libraries-install-python

natural language api

サンプルコードはここ
https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/language/cloud-client/v1

環境構築

speech apiと同様に、該当のディレクトリに移動して以下のコマンドを実行

pip install -r requirements.txt

動作確認

python quickstart.py

speech apiと同様に下記のコードの方がオススメ
https://cloud.google.com/natural-language/docs/reference/libraries?hl=ja

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4