Goal: 「IoTデータ分析環境立ち上げ on GCP」の環境に対して、Iphoneから位置情報データをPushするサンプル。Iphoneをエッジ端末として活用して、色々できそう。
How
0. 前準備 Pythonista関連
a)Pythonista のインストール
https://apps.apple.com/jp/app/pythonista-3/id1085978097
b)Gitを使いたかったら、stashをインストール
https://github.com/ywangd/stash
c)説明サイト ググったらたくさんあると思いますが、私は、以下のリンクを参照させていただきました。ありがとうございました。
http://hitoriblog.com/?p=42145#Python-5
1. Pythonista を使って、端末の位置情報、スピード等を取得する
a)Iphone上で、位置情報などを確認してみる
2. GCPのPub/Subにパブリッシュする。これの詳細は、前出のブログを参照
a)GCP提供のサンプルプログラムをベースに追加加工する。
https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/iot/api-client/mqtt_example
をローカルPCにクローンして、Pythonの環境などをセットする。
cloudiot_mqtt_example.pyをベースに変更を加えたものが以下。
Oracle Application Express Notes | Apps development Notes | Google Cloud Platform | Python | apps test | Cool Beans | English | Books
2019/07/27
2018/09/02
GCP: GCP外のサーバーからDatastoreへデータをインポートする(GCPのKeyを使う場合)
- Goal
タブ区切りのテキストファイルをローカルマシン(OR AWSのEC2でも同じ)GCPのDatastoreにインポートする。pythonのプログラムで実施。
前のPOSTのKeyを自分で設定しないバージョン - Case
以下のようなテキストファイルを、Datastoreにインポートする。
想定するのは、DatastoreをGAEのマスタのように利用していて、バッチで更新をするようなケース。keyは、GCPで自動設定されるKeyを使う。
list.txtの中身(タブ区切り)
id shimei score
1234 山田 89
2341 田中 90
1238 佐藤 81 - How
1.GCPのコンソールで、Service Account Keyを作成する
形式は、JSON
権限は、DatastoreのOwner(これは、Import&Exportでも良いのかも?)
作成された、JSONはローカルマシンのどこかに設置する。
2.Google cloud datastore のクライアントライブラリをインストールする。
~$ pip install google-cloud-datastore
3.pythonのプログラムでインポートする。
##utf-8に変換⇒Unicodeに変換して、インポートすること!
あとで、Pythonから呼び出しをする事を想定している。 - Result
ラベル:
GCP,
Google Cloud Platform,
python,
開発環境,
仕事
GCP: GCP外のサーバーからDatastoreへデータをインポートする(keyを自分で設定する場合)
- Goal
タブ区切りのテキストファイルをローカルマシン(OR AWSのEC2でも同じ)GCPのDatastoreにインポートする。pythonのプログラムで実施。
Keyは自分で設定したい。
Keyを自分で設定する必要がない場合はこちら。 - Case
以下のようなテキストファイルを、Datastoreにインポートする。
想定するのは、DatastoreをGAEのマスタのように利用していて、バッチで更新をするようなケース。id をKeyとして登録したい。
list.txtの中身(タブ区切り)
id shimei score
1234 山田 89
2341 田中 90
1238 佐藤 81 - How
1.GCPのコンソールで、Service Account Keyを作成する
形式は、JSON
権限は、DatastoreのOwner(これは、Import&Exportでも良いのかも?)
作成された、JSONはローカルマシンのどこかに設置する。
2.Google cloud datastore のクライアントライブラリをインストールする。
~$ pip install google-cloud-datastore
3.pythonのプログラムでインポートする。
##utf-8に変換⇒Unicodeに変換して、インポートすること!
あとで、Pythonから呼び出しをする事を想定している。 - Result
ラベル:
GCP,
Google Cloud Platform,
python,
開発環境,
仕事
2018/08/15
GCP: gcloud のバージョンアップ時のエラーと解消方法 on Windows Subsystem for Linux
- GAEのFlexible environmentを利用するにあたり、コンソール画面でデプロイしたソースを見れるようにするには、gcloudを195以上にしないと駄目らしい。
- 188から最新版にUPDATEしようとしたら、エラーが出たので経緯と対応手順メモ
- 開発環境は、Windows10+Bash on windows(Ubuntu 16.04.3)
以下、ログ
~# gcloud components update
# 普通にアップデートしようとしたら以下のエラー
~# gcloud components update
# 普通にアップデートしようとしたら以下のエラー
ERROR: (gcloud.components.update)
You cannot perform this action because the Cloud SDK component manager is disabled for this installation. You can run the following command to achieve the same result for this installation:
sudo apt-get update && sudo apt-get --only-upgrade install kubectl google-cloud-sdk google-cloud-sdk-datastore- emulator google-cloud-sdk-pubsub- emulator google-cloud-sdk-app-engine-go google-cloud-sdk-app-engine- java google-cloud-sdk-app-engine- python google-cloud-sdk-cbt google-cloud-sdk-bigtable- emulator google-cloud-sdk-app-engine- python-extras google-cloud-sdk-datalab
~# sudo -E apt-get update
# 私の環境では −E が必要
Hit:1 http://archive.ubuntu.com/ ubuntu xenial InRelease
Get:2 http://packages.cloud.google. com/apt cloud-sdk-xenial InRelease [6,372 B]
Err:2 http://packages.cloud.google. com/apt cloud-sdk-xenial InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6A030B21BA07F4FB
(省略)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.cloud.google. com/apt cloud-sdk-xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6A030B21BA07F4FB
(省略)
# よくわからないけど、Public Key が使えないとかなんとか。。。
# Google Groupsのトピによると、以下でKeyを追加せよとのこと
~# curl https://packages.cloud.google. com/apt/doc/apt-key.gpg | apt-key add -
% Total % Received % Xferd Average Speed Time Time Time Current
100 1326 100 1326 0 0 2062 0 --:--:-- --:--:-- --:--:-- 2062
OK
# 再トライ
~# sudo -E apt-get update
Get:1 http://packages.cloud.google. com/apt cloud-sdk-xenial InRelease [6,372 B]
Hit:2 http://archive.ubuntu.com/ ubuntu xenial InRelease
Get:3 http://packages.cloud.google. com/apt cloud-sdk-xenial/main amd64 Packages [45.3 kB]
Hit:4 http://archive.ubuntu.com/ ubuntu xenial-updates InRelease
Get:5 http://security.ubuntu.com/ ubuntu xenial-security InRelease [107 kB]
Fetched 158 kB in 1s (84.8 kB/s)
Reading package lists... Done
# うまくいった
# つづいて、SDKのUPDATE 余計なパッケージ名もあるけど、そのまま実行
~# sudo -E apt-get --only-upgrade install kubectl google-cloud-sdk google-cloud-sdk-datastore- emulat
or google-cloud-sdk-pubsub- emulator google-cloud-sdk-app-engine-go google-cloud-sdk-app-engine- java google-cloud-sdk-app
-engine-python google-cloud-sdk-cbt google-cloud-sdk-bigtable- emulator google-cloud-sdk-app-engine- python-extras google-
cloud-sdk-datalab
Reading package lists... Done
Building dependency tree
Reading state information... Done
Skipping google-cloud-sdk-app-engine- go, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-app-engine- java, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-app-engine- python, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-app-engine- python-extras, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-bigtable- emulator, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-cbt, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-datalab, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-datastore- emulator, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-pubsub- emulator, it is not installed and only upgrades are requested.
Skipping kubectl, it is not installed and only upgrades are requested.
The following package was automatically installed and is no longer required:
snap-confine
Use 'sudo apt autoremove' to remove it.
Suggested packages:
google-cloud-sdk-app-engine- java google-cloud-sdk-app-engine- python google-cloud-sdk-pubsub- emulator
google-cloud-sdk-bigtable- emulator google-cloud-sdk-datastore- emulator kubectl
The following packages will be upgraded:
google-cloud-sdk
1 upgraded, 0 newly installed, 0 to remove and 155 not upgraded.
Need to get 19.2 MB of archives.
After this operation, 28.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://packages.cloud.google. com/apt cloud-sdk-xenial/main amd64 google-cloud-sdk all 212.0.0-0 [19.2 MB]
Fetched 19.2 MB in 11s (1,652 kB/s)
(Reading database ... 50185 files and directories currently installed.)
Preparing to unpack .../google-cloud-sdk_212.0.0- 0_all.deb ...
Unpacking google-cloud-sdk (212.0.0-0) over (188.0.1-0) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up google-cloud-sdk (212.0.0-0) ...
# 完了
~# gcloud --version
Google Cloud SDK 212.0.0
alpha 2018.08.13
beta 2018.08.13
bq 2.0.34
core 2018.08.13
gsutil 4.33
2018/02/24
Docker CE のディレクトリを引っ越しする方法
AWSのEC2 RHEL7.4 にDocker CEをセットアップする手順 の後に、Rootディレクトリを引っ越しする方法
・システム領域のハードディスクを大量に消費するので、別ディレクトリへ引っ越しする
以下の例は、/var/lib/docker から /xxx/mnt/docker/ へ引越し
0.初期設定確認
1.ServiceSTOP
2.ディレクトリを作ってコピー
3.設定変更
4.ServiceStart
2017/12/02
Pyenv + virtualenv のセットアップ手順 on AWS-EC2
AWSのEC2 RHEL7.4(Ubuntuの場合は、パッケージの部分だけ違う) に Pyenv+virtualenv をセットアップする手順
1.インストール
2.チェックとちょこっと設定
#切り替え可能なバージョンチェック
1.インストール
2.チェックとちょこっと設定
#切り替え可能なバージョンチェック
[ec2-user@ip-10-0-0-174 ~]$ pyenv versions
* system (set by /home/ec2-user/.pyenv/version)
#インストール可能なPythonバージョンを確認
#インストール可能なPythonバージョンを確認
[ec2-user@ip-10-0-0-174 ~]$ pyenv install -l
Available versions:
2.1.3
2.2.3
2.3.7
2.4
2.4.1
2.4.2
#新しいPythonのバージョンをインストール
#新しいPythonのバージョンをインストール
[ec2-user@ip-10-0-0-174 ~]$ pyenv install 2.7.13
Downloading Python-2.7.13.tar.xz...
-> https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
Installing Python-2.7.13...
Installed Python-2.7.13 to /home/ec2-user/.pyenv/versions/2.7.13
#2.7.13が追加された。
[ec2-user@ip-10-0-0-174 ~]$ pyenv versions
* system (set by /home/ec2-user/.pyenv/version)
2.7.13
#2.7.13をベースに、"testpy"という環境を構築する
#2.7.13をベースに、"testpy"という環境を構築する
[ec2-user@ip-10-0-0-174 ~]$ pyenv virtualenv 2.7.13 testpy
Collecting virtualenv
Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
100% |████████████████████████████████| 1.8MB 638kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
New python executable in /home/ec2-user/.pyenv/versions/2.7.13/envs/testpy/bin/python2.7
Also creating executable in /home/ec2-user/.pyenv/versions/2.7.13/envs/testpy/bin/python
Installing setuptools, pip, wheel...done.
Requirement already satisfied: setuptools in /home/ec2-user/.pyenv/versions/2.7.13/envs/testpy/lib/python2.7/site-packages
Requirement already satisfied: pip in /home/ec2-user/.pyenv/versions/2.7.13/envs/testpy/lib/python2.7/site-packages
#"testpy"が追加された
#"testpy"が追加された
[ec2-user@ip-10-0-0-174 ~]$ pyenv versions
* system (set by /home/ec2-user/.pyenv/version)
2.7.13
2.7.13/envs/testpy
testpy
#開発用のディレクトリ"pyproject"のPython環境を"testpy"に変更する
バージョン2.7.13へと変更された。
#開発用のディレクトリ"pyproject"のPython環境を"testpy"に変更する
[ec2-user@ip-10-0-0-174 ~]$ cd pyproject/
#今のバージョンは、2.7.5だが。。
#今のバージョンは、2.7.5だが。。
[ec2-user@ip-10-0-0-174 pyproject]$ python -V
Python 2.7.5
#Pyenvで変更すると
#Pyenvで変更すると
[ec2-user@ip-10-0-0-174 pyproject]$ pyenv local testpy
(testpy) [ec2-user@ip-10-0-0-174 pyproject]$ python -V
Python 2.7.13
バージョン2.7.13へと変更された。
登録:
投稿 (Atom)

