Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I installed MicroPython v1.9.3-8 on my ESP8266 board. Here is the beginning of my main.py file:

from machine import Pin
led = Pin(2, Pin.OUT, value=1)
#---MQTT Sending---
from time import sleep_ms
from ubinascii import hexlify
from machine import unique_id
#import socket
from umqtt import MQTTClient
SERVER = "10.6.6.192"
CLIENT_ID = hexlify(unique_id())
TOPIC1 = b"/server/tem"
TOPIC2 = b"/server/hum"
TOPIC3 = b"/server/led"

The line from umqtt import MQTTClient throws an error when I reset the module:

File "main.py", line 11, in < module >

ImportError: no module named 'umqtt.MQTTClient'

Here is my umqtt.py file.

I have the umqtt.py file uploaded to my esp8266 with webrepl. When I run:

import os
os.listdir()

I get this output:

>>> os.listdir()
['boot.py', 'webrepl_cfg.py', 'umqtt.py', 'main.py']

Since in the umqtt.py file in line 8 the class MQTTClient is defined, I do not know what am I doing wrong to get this code to work.

You may have moved on or found a solution, but it might help to know what the value of sys.path is just before the import is attempted. – craigts Feb 15, 2018 at 14:52 Hi! What does python umqtt.py says after adding to umqtt.py the following code: if __name__ == "__main__": print("Module umqtt") ? – karol Feb 15, 2018 at 20:43 Can you do a import umqtt and then do print(dir(umqtt)) and post that log. Either you have a pyc file or you have your path set incorrect and have another version of umqtt in some other path as well – Tarun Lalwani Feb 16, 2018 at 10:55

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.