Installing libraries on ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

Re: Installing libraries on ESP32

Post by guyd » Fri Jul 27, 2018 12:19 pm

pythoncoder wrote:
Tue Jul 24, 2018 5:59 am
You should be able to install it using upip as described. What happens when you try?

Alternatively just copy datetime.py from micropython-lib to the ESP32: this should work as it's a simple library comprising just that one file. I have a clone of micropython-lib on my local hardware for such purposes.

Copied to root directory of pyboard, and got this message;

Code: Select all

>>> import datetime
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 136 bytes
>>> 

User avatar
pythoncoder
Posts: 4573
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Installing libraries on ESP32

Post by pythoncoder » Sat Jul 28, 2018 6:52 am

I hadn't spotted how big datetime.py is. Looking at the code it's the CPython 3.5 version, lightly modified. There is a case for a "micro" subset to be written.

If it's throwing a memory error on import immediately after a boot, it's too big for the target's RAM. Your best hope is to cross-compile it and copy the datetime.mpy to the target. Failing that you'll need to use frozen bytecode. Or use an ESP32 with SPIRAM and the Loboris port.

I suppose a last resort is to roll your own alternative by stripping out any functionality you don't need.
Peter Hinch

guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

Re: Installing libraries on ESP32

Post by guyd » Thu Aug 02, 2018 11:19 am

Hi,
I try again to use datetime.py library ( after reflashing MicroPython again ).
As you suggested before - just copied datetime.py to ESP32 main directory.

additional services loaded: 1) wifi connection, 2)update RTC, both went successfully.

now again when I try to import datetime- I get a memery allocation err, as show before.

Can you explain what do I do wrong ?

Guy

SpotlightKid
Posts: 420
Joined: Wed Apr 08, 2015 5:19 am

Re: Installing libraries on ESP32

Post by SpotlightKid » Thu Aug 02, 2018 12:28 pm

Nothing. pythoncoder already explained to you what is going on in his last reply in the second paragraph.

Please read this for further explanation: http://docs.micropython.org/en/latest/e ... ained.html

User avatar
Roberthh
Posts: 2176
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Installing libraries on ESP32

Post by Roberthh » Thu Aug 02, 2018 1:09 pm

@pythoncoder:
Or use an ESP32 with SPIRAM and the Loboris port.
The micropython.org port also supports SPIRAM. https://github.com/micropython/micropyt ... 092ee354b0

zelezni
Posts: 1
Joined: Sun Oct 18, 2020 4:04 pm

Re: Installing libraries on ESP32

Post by zelezni » Sun Oct 18, 2020 4:18 pm

This is rather old post, but hopefully my answer will prevent someone to spend "hours" looking for a solution (as I just did):

I am on Windows. In command prompt first navigate to a folder, where you've installed rshell. Activate it and enter repl. Then:

Code: Select all

import upip
upip.install('<desired_package_name>')
Example:

Code: Select all

upip.install('urllib.parse')
So, you are installing module directly on the board. Note that board needs to be connected to the internet for this to work.


Happy coding!

MrR^2
Posts: 3
Joined: Fri Aug 02, 2019 3:44 pm

Re: Installing libraries on ESP32

Post by MrR^2 » Thu Oct 22, 2020 2:32 am

Hello,
Another way to get an easy repl on Windows is to use UPycraft.
~MrR^2

Post Reply