LoginSignup
3
3

More than 5 years have passed since last update.

【備忘録】Linux上でAzure IoT HubのPython用SDKをセットアップした話

Posted at

あらすじ

Microsoft Azure上のサービスの一つであるAzure IoT Hubを
Python3.x系から使うためのSDKをインストールしようとした時のお話。

いつもどおり「azure iot sdk」とググって情報を集めはじめた所、
以下のサイトがヒット。

https://docs.microsoft.com/ja-jp/azure/iot-hub/iot-hub-python-getstarted

上記サイトによると、pipでインストール可能なパッケージとして、
以下が既に存在しているとのこと。

・azure-iothub-service-client
・azure-iothub-device-client

何も考えずに以下を入力。

pip install azure-iothub-service-client

しかし。

Downloading/unpacking azure-iothub-service-client
  Could not find any downloads that satisfy the requirement azure-iothub-service-client
Cleaning up...
No distributions at all found for azure-iothub-service-client
Storing debug log for failure in /root/.pip/pip.log

エラー吐きました。

上のサイトをよく見てみると…
「azure-iothub-service-clientとazure-iothub-device-clientのpipパッケージは、WindowsOSでのみ利用可能」
という旨の記載が。Linuxから使う場合は、別の方法でインストールする必要があるとのこと。

githubからパッケージをcloneしてビルド。

さくっとclone。

git clone --recursive https://github.com/Azure/azure-iot-sdk-python.git

サブモジュールとしてリポジトリに含まれているファイルもビルドで必要になるので、
cloneする時は--recursiveオプションを付ける必要があります。

cloneが終わったら、以下を参考に…

https://github.com/Azure/azure-iot-sdk-python/blob/master/doc/python-devbox-setup.md#linux

ビルドとインストールをしてくれるスクリプトがあるので、そこまで移動します。

cd azure-iot-sdk-python/build_all/linux/

Python3.4用にビルドしたかったので、以下のようにしました。
--python-version、--build-pythonのオプションを省くと、
いずれも2.7用としてセットアップ/ビルドされるようです。

sudo ./setup.sh --python-version 3.4
sudo ./build.sh --build-python 3.4

build.shが成功すれば、Python3.4環境下でimport出来るようになります。

以上、備忘録まで。

3
3
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
3
3