Hi, i need to install some python libraries into a ESP8266. I tried by Thonny but can’t find no way to do this.
I could copy the libraries/packages into the board but it’s not easy task to solve all the dependencies.
By Thonny “Manage plug-ins” menu I can install a library into my Thonny instance but I couldn’t understand how to transfer it to the board.
Btw I see pyserial installed in Thonny but trying to import it in the REPL gives an error:
import pyserial Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: no module named 'pyserial'
Please, any hint? Thanks.
Hi, i need to install some python libraries into a ESP8266. I tried by Thonny but can’t find no way to do this.
I could copy the libraries/packages into the board but it’s not easy task to solve all the dependencies.
By Thonny “Manage plug-ins” menu I can install a library into my Thonny instance but I couldn’t understand how to transfer it to the board.
Btw I see pyserial installed in Thonny but trying to import it in the REPL gives an error:
import pyserial Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: no module named 'pyserial'
Please, any hint? Thanks.
Hi Enzo.
What Python libraries do you need to include?
You need to copy the library file into the ESP8266. Like you would do to upload the code.
There is the micropython version for some of the most popular python libraries. Usually, it’s the original name of the library preceded by “u”.
Regards,
Sara
Hi Sara, now I need pyserial (or serial) but I’ll need other not included as standard in upython.
I tried to import pyserial but it says there’s no such module.
I know I can copy them “manually” but in some cases, as for pyserial, in the GIT rep I found many parts and to study each of them to understand what are needed to run correctly is not a quick task! And include all parts for all libraries needed eats a lot of memory leaving little room for my code.
Nice regards,
Enzo
And I see in standard micropython I flashed into my ESP8266 (MicroPython v1.12-388-g388d419ba on 2020-04-21) pip isn’t installed: it’s installed in Thonny but can’t understand how to tell it to install a chosen package into the board!
Hi again.
Unfortunately, I’m not familiar with that subject.
Maybe this documentation will help: https://docs.micropython.org/en/latest/reference/packages.html
Regards,
Sara
Thanks Sara,
I’ll try to understand because micropython reference isn’t the best example of documentation 🙂
Ok.
Meanwhile, if you find out something, please share.
It may be useful for our readers.
Regards,
Sara
Hi Enzo,
I am not sure if is possible to use pyserial in micropython.
To include libraries into the esp8266 board you can use the upip comand. So, the recipe:
1- open Thonny and connect the board.
2- the board has to be connect to the wifi network. Execute this code as boot.py
import micropython
import network
import esp
esp.osdebug(None)
import gc
gc.collect()
ssid = ‘xxx’
password = ‘xxx’
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect(ssid, password)
while station.isconnected() == False:
pass
print(‘Connection successful’)
print(station.ifconfig())
3- write and execute this comand: “import upip”
4- and this one: “upip.install(“library name”)”. For example, upip.install(“urequests”). All available libraries can be find here, https://github.com/micropython/micropython-lib . Note that pyserial is not there.
5- in the board a directory \lib is created with the library inside.
Regards, Luiz