Page 1 of 1

[SOLVED] Version 1.18 cannot import frozen modules, ImportError

Posted: Tue Jan 25, 2022 7:09 pm
by BetterAutomations
What do I need to do to import frozen modules with 1.18? This worked fine under 1.16.

Code: Select all

>>> import _main
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named '_main'
>>> 

Re: Version 1.18 cannot import frozen modules, ImportError

Posted: Tue Jan 25, 2022 8:45 pm
by BetterAutomations
I see something in the release notes about frozen modules but I don't understand how it impacts me, or how to work with this.
Support for FROZEN_DIR and FROZEN_MPY_DIR has been deprecated for some time and was finally removed in this release. Instead of these, FROZEN_MANIFEST can be used. The io.resource_stream() function is also removed, replaced by the pure Python version in micropython-lib.

The search order for importing frozen Python modules is now controlled by the ".frozen" entry in sys.path. This string is added by default in the second position in sys.path. User code should adjust sys.path depending on the desired behaviour. Putting ".frozen" first in sys.path will speed up importing frozen modules.

Code: Select all

>>> import sys
>>> sys.path
['/lib', '/fresh', '']
>>> 

Re: [SOLVED] Version 1.18 cannot import frozen modules, ImportError

Posted: Tue Jan 25, 2022 9:06 pm
by BetterAutomations
Solved. I was adding a custom path to sys.path and removing all other paths and accidentally removed .frozen as well. Now that I leave it alone, my sys.path is correct:

Code: Select all

>>> import sys
>>> sys.path
['', '.frozen', '/lib']
>>> import _main
>>>