How to fix Python ModuleNotFoundError: No module named 'paho'

Problem:

When running your Python script, you see an error message like

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import paho.mqtt.client as mqtt
ModuleNotFoundError: No module named 'paho'

Solution

Install theĀ paho-mqtt package using

pip3 install paho-mqtt

or

pip install paho-mqtt