I get this error message:
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ImportError: no module named ‘DateTime’
Can you provide more details about your issue?
What did you install and how? And what code are you trying to run?
You’re probably getting that error because the module you’re trying to import is not “installed/uploaded” to your board.
I use the “Manage Plug-ins” in Tools of Thonny. I enter the package I want imported and press “Find package from PyPI”. The package is installed and I can see the package imported in the list on the left. It is also in the folder “home/user/.local/lib/python3.7/site-packages”. I’m trying to install DateTime and schedule packages so I can use them to code. However, when I import the package, Thonny gives me the error I previously mentioned.
Thonny IDE is a Python IDLE that also supports MicroPython on ESP32/ESP8266 devices. This means you can also write Python programs and run then on your computer.
When you install packages as you did, you’re installing the packages locally on your computer. This would work if you were running Python on your computer.
In this case, you’re running MicroPython not on your computer, but on your ESP32 or ESP8266 boards. So the libraries need to be installed/imported to the ESP boards.
By default, you can use the utime library: http://docs.micropython.org/en/latest/library/utime.html
You can also import the datetime library adapted for MicroPython: https://github.com/micropython/micropython-lib/blob/master/datetime/datetime.py
Basically, create a file called datetime.py with the datetime.py content and import it to the ESP32 board. Then, you can use the library functions on your code. Learn more about installing libraries on the eBook, page 351.
I hope this helps.
A newbie mistake. I use Thonny to flash my ESP8266 and did not change back the python interpreter back to the default used by Thonny and the current python program after I finished flashing. I hope this helps others.