[Windows] New frozen module not present in executable

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
stijn
Posts: 507
Joined: Thu Apr 24, 2014 9:13 am

Re: [Windows] New frozen module not present in executable

Post by stijn » Tue Sep 08, 2020 12:20 pm

Ok. Strange problem, sounds like a bug with how sys.path gets set, or could be documented behavior but I didn't immediately find such thing in the documentation.

I'll be working on getting freezing to work with the msvc port as well, and report back here when that works. Might be a while due to busy schedule though.

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

Re: [Windows] New frozen module not present in executable

Post by jimmo » Tue Sep 08, 2020 1:43 pm

stijn wrote:
Tue Sep 08, 2020 12:20 pm
Ok. Strange problem, sounds like a bug with how sys.path gets set, or could be documented behavior but I didn't immediately find such thing in the documentation.
I think this is a bug ... hopefully just in the Unix (and Windows) ports.

What's happening here is that when running the Unix/Windows executable with a filename.py, sys.path will be ['/path/containing/filename.py', '/home/jimmo/.micropython/lib', '/usr/lib/micropython'] whereas when running without a filename it will be ['', '/home/jimmo/.micropython/lib', '/usr/lib/micropython']

When you "import mymodule" it will try this in each of the sys.path entries. But :/path/containing/filename.py/mymodule" doesn't match the frozen module whereas "mymodule" does.

So the workaround is to add:

import sys
sys.path.append('')

to the top of your program.

But this seems like a bug... I'm just not sure right now what the correct fix is.


stijn
Posts: 507
Joined: Thu Apr 24, 2014 9:13 am

Re: [Windows] New frozen module not present in executable

Post by stijn » Thu Sep 10, 2020 12:14 pm

And see https://github.com/micropython/micropython/pull/6428 for support for freezing via manifest for the windows ports

Post Reply