【Python】MQTTを実装したクライアントライブラリ「paho-mqtt」のインストールについて解説しています。なお、MQTT(Message Queuing Telemetry Transport)は、軽量かつ効率的なメッセージングプロトコルであり、M2M(Machine-to-Machine)通信やIoT(Internet of Things)アプリケーションなど、さまざまな分野で広く使用されている。
「paho-mqtt(https://eclipse.dev/paho/)」は、Eclipse Pahoプロジェクトによって開発されており、さまざまなプログラミング言語向けに提供されています。Python以外でも利用できるため、さまざまなプラットフォームやデバイス上でMQTT通信を実装できます。
■Python
今回のPythonのバージョンは、「3.10.9」を使用しています。(Windows11)(pythonランチャーでの確認)
■paho-mqttをインストールする
paho-mqttをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。
pip install paho-mqtt
起動後、上記のコマンドを入力し、Enterキーを押します。
なお、今回は、pythonランチャーを使用しており、Python Version 3.10.9にインストールを行うために、バージョンの切り替えを行います。
py -3.10 -m pip install paho-mqtt
切り替えるために、上記のコマンドを入力し、Enterキーを押します。
Defaulting to user installation because normal site-packages is not writeable Collecting paho-mqtt Downloading paho-mqtt-1.6.1.tar.gz (99 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 99.4/99.4 kB 948.2 kB/s eta 0:00:00 Preparing metadata (setup.py) ... done Installing collected packages: paho-mqtt DEPRECATION: paho-mqtt is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559 Running setup.py install for paho-mqtt ... done Successfully installed paho-mqtt-1.6.1
Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、paho-mqttが正常にインストールされたことになりますが、「DEPRECATION」が表示され、これはPython開発者へ向けての警告となります。エラーではないので、一旦無視しています。
なお、今回はpaho-mqttのバージョン1.6.1をインストールしました。
コメント