メイン コンテンツにスキップ

 Subscribe

Since the release in 2016, developers are using our Azure IoT Python SDK to write device and back-end applications to connect to Azure IoT Hub and Device Provisioning Service, as well as writing modules for Azure IoT Edge (preview). Python is a popular choice for prototyping, and it is gaining traction in the embedded world.

If you decide to use the Python SDK for development, there are few things you should keep in mind: Python SDK is a wrapper on top of our Azure IoT C SDK, and we release binary packages on pip for Windows, Ubuntu, and Raspbian, all of which are compatible with Python 2 and Python 3. This approach has its ups and downs. On the upside, the features you see in C are available in Python with no functionality difference. On the downside, it is not a native Python SDK. Application Programming Interfaces (APIs) that we exposed may look different from typical Python APIs; and as a developer, you will need to pay attention the architecture of underlying platform, especially when you are using pip!

At a high level, there are three things that must align to reference the Python SDK properly: Python version (2 or 3), system architecture (x86 or x64) and pip reference (Python 2 or Python 3). This combination leads to common errors such as packages are installed using pip for Python 2, but the script is run with Python 3; Python x86 is installed for an x64 machine, and more. These tips should help with common errors based on your development environment.

Windows

Windows does not have Python pre-installed. The default installer on python.org is x86, which may not be the architecture of your PC. The processor type information is available in Windows Settings. If your system is x64 processor-based, you need to download the x86-64 installer from Python.

Ubuntu

Ubuntu has Python 2 installed and it cannot be removed from the OS. However, if you upgrade the system using sudo apt, be sure to install Python 3 on the machine. Ubuntu still uses Python 2 by default with pip, so there won’t be any issues if you are trying to use Python 2. If you plan on using Python 3, be sure to install the SDK using pip for Python 3 and run the script with Python 3.

Raspbian (Raspberry Pi)

Raspbian is a distribution of Linux, so it has similar behavior to Ubuntu. Python 2 is installed and cannot be removed. When you upgrade the system, Python 3 is also installed on the machine. Unfortunately, pip defaults to Python 3 but the OS defaults to Python 2 when you try to run the script. This causes a not found error because the package is installed on a different Python.Python 2 users should install with pip for Python 2, and Python 3 users should run with python3 instead of python.

MacOS

Currently, the Python SDK does not provide pip packages for MacOS. This is work in progress and will be available soon. In the meantime, you can build the SDK following instructions.

 

We hope this has been helpful! We are continuously working on improving the experience for Python developers, including working with the boost library and using pip packages. Stay tuned for more announcements in this area!

  • Explore

     

    Let us know what you think of Azure and what you would like to see in the future.

     

    Provide feedback

  • Build your cloud computing and Azure skills with free courses by Microsoft Learn.

     

    Explore Azure learning


Join the conversation