Environment requirements and configuration
This topic describes the recommended development environment for the Python Link SDK and how to configure it.
Environment configuration
Use Python 3.6 or later.
The Python Link SDK has been tested on the following operating systems. To prevent errors during development and at runtime, we recommend that you use one of these environments.
Linux: Ubuntu 18.04 64-bit or later.
Windows: Windows 7 64-bit or later.
macOS: High Sierra.
Prerequisites
This topic uses Python 3.6 as an example. If you use a later version, replace the version number
python3.6in the commands with your version number, such aspython3.9.The commands in this topic are run with regular user permissions. If an operation requires administrative permissions, prefix the command with
sudo.
Install Python 3.6
Linux and macOS
Step 1: Install Python 3 tools
If you have Python 3.6 or later installed, skip this step.
Linux
Install from the command line or from source:
Command-line installation: For Ubuntu 18.04 and later.
sudo apt-get update sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get install wget python3.6Source installation: For operating systems that do not support command-line installation, you must install from a source package.
sudo apt-get install wget gcc make zlib1g-dev wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz tar -xf Python-3.6.7.tgz cd Python-3.6.7 ./configure make -j sudo make install
macOS
Download the installer from the following link: macOS download.
Step 2: Install PIP
Obtain the PIP script.
For Python 3.6:
wget https://bootstrap.pypa.io/pip/3.6/get-pip.pyFor Python 3.7 and later:
wget https://bootstrap.pypa.io/get-pip.py
Install PIP.
The following command installs PIP for Python 3.6. If you are using a later version, replace the version number
python3.6in the command with your version number, such aspython3.9.sudo apt-get install python3-distutils sudo python3.6 get-pip.py
Step 3: Install setuptools, wheel, and venv
To compile and run the device software development kit (SDK), you must install the setuptools package management tool, the wheel build dependency, and venv (Virtual Environment).
Run the following commands:
python3.6 -m pip install --upgrade pip setuptools wheel
sudo apt-get install python3.6-venvWindows
Select an installer based on your system architecture:
Download the demo
Download the demo files from the following link: Get example code.
Configure the environment
Use paho-mqtt version 1.4.0 or 1.5.1. These versions have passed stress tests. You can run the pip list command to check the paho-mqtt version.
Linux and macOS
Create and activate a virtual environment.
Install the Link SDK using either the automatic or manual method.
Automatic installation
Run the following command to install paho-mqtt version 1.4.0.
pip install paho-mqtt==1.4.0Run the following command to install the latest version of the Link SDK.
pip install aliyun-iot-linkkitManual installation
Download the Link SDK and the required open source MQTT library: Get the latest version of the Python Link SDK, Get the open source paho-mqtt library.
The latest version of Link SDK is 1.2.13.
Place the aliyun-iot-linkkit-1.2.13.tar.gz and paho-mqtt-1.4.0.tar.gz files in the work_dir folder, and then run the following commands:
tar zxvf paho-mqtt-1.4.0.tar.gz cd paho-mqtt-1.4.0 python3 setup.py install cd .. tar zxvf aliyun-iot-linkkit-1.2.13.tar.gz cd aliyun-iot-linkkit-1.2.13 python3 setup.py install cd ..
mkdir work_dir
cd work_dir
python3.6 -m venv test_env
source test_env/bin/activate
pip install wheel Windows
Create and activate a virtual environment.
mkdir work_dir cd work_dir python3.6 -m venv test_env test_env\Scripts\activate.batInstall the Link SDK using either the automatic or manual method.
Automatic installation
Run the following command to install paho-mqtt version 1.4.0.
pip install paho-mqtt==1.4.0Run the following command to install the latest version of the Link SDK.
pip install aliyun-iot-linkkit
Manual installation
Download the Link SDK and the required open source MQTT library: Get the latest version of the Python Link SDK, Get the open source paho-mqtt library.
The latest version of Link SDK is 1.2.13.
Place the paho-mqtt-1.4.0.tar.gz and aliyun-iot-linkkit-1.2.13.tar.gz files in the work_dir folder, extract them, and then run the following commands.
cd paho-mqtt-1.4.0 python setup.py install cd .. cd aliyun-iot-linkkit-1.2.13 python setup.py install cd ..
Log switch
You can enable internal log output for the SDK.
import logging
__log_format = '%(asctime)s-%(process)d-%(thread)d - %(name)s:%(module)s:%(funcName)s - %(levelname)s - %(message)s'
logging.basicConfig(format=__log_format)To enable debug logging, use the following method:
lk_auth.enable_logger(logging.DEBUG)