Memory Error, Memory Allocation Error of 136 bytes when trying import

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
Charlython
Posts: 1
Joined: Tue Jun 23, 2020 10:56 pm

Memory Error, Memory Allocation Error of 136 bytes when trying import

Post by Charlython » Tue Jun 23, 2020 11:13 pm

I have a proyect and im using a SiPy to develop it, when i add a couple of new files to the proyect i tried to run the proyect to see that doesn't affect the proyect itself, but suddenly a
MemoryError: Memory Allocation failed, allocating 136 bytes
rised on the atom terminal, about a line that imports another class of the proyect, one that doesn't interfere with the new added.
I search a lot of information about it and i see some possibilities about allocate bytecode on the flash or something like that (sorry for bad expressions, not even my first year as software developer), and i tried to format my flash to clean the board (with os.fsformat("/flash")) and uploading it again to find out i have the same error.
if i comment that import line i catch the same error later on another import of an imported class also and so on...
I don't really know if there is some easy troubleshooting but i've been stuck for a week with this problem and i am out of ideas.
print("Thanks people").

User avatar
jimmo
Posts: 1710
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Memory Error, Memory Allocation Error of 136 bytes when trying import

Post by jimmo » Mon Jun 29, 2020 6:40 am

It sounds like it's running out of RAM trying to compile and the module that is being imported.

The feature you're looking for is called "frozen modules" and it lets you pre-compile python code as bytecode into the firmware image. Which port and board are you using?

For the "main" MicroPython ports (STM32, ESP32, ESP8266, etc) you'll need to write a manifest.py describing which files to use. I'm not sure the equivalent thing for the PyCom boards, but it would be worth asking in the PyCom forums.

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

Re: Memory Error, Memory Allocation Error of 136 bytes when trying import

Post by Roberthh » Mon Jun 29, 2020 7:47 am

For the Pycom firmware you have to put your files into the folder frozen/Custom. Then they will be included into the flash during the build process.

Post Reply