• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

how to install Python libraries into esp8266?

Q&A Forum › how to install Python libraries into esp8266?
0 Vote Up Vote Down
Enzo Pontone asked 5 years ago

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.

9 Answers
0 Vote Up Vote Down
Enzo Pontone answered 5 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

0 Vote Up Vote Down
Enzo Pontone answered 5 years ago

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

0 Vote Up Vote Down
Enzo Pontone answered 5 years ago

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!

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

0 Vote Up Vote Down
Enzo Pontone answered 5 years ago

Thanks Sara,
I’ll try to understand because micropython reference isn’t the best example of documentation 🙂

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Ok.
Meanwhile, if you find out something, please share.
It may be useful for our readers.
Regards,
Sara

0 Vote Up Vote Down
Luiz Sampaio answered 5 years ago

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
 

0 Vote Up Vote Down
Enzo Pontone answered 5 years ago

Thanks Luiz,
I tried something like this some days ago but the library was never “completely installed” and I couldn’t understand why!
I’ll try again and let you know if it’s ok or the exact error message.
Thanks for your answer 🙂
Enzo

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.