You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unix: sys.path affects loading of frozen modules #6419
$ ./micropython ~/mpy/demo.py
Traceback (most recent call last):
File "/home/jimmo/mpy/demo.py", line 5, in <module>
ImportError: no module named 'mymodule'
The underlying issue here is that the unix port, when running normally has sys.path=["", "~/.micropython/lib:/usr/lib/micropython"], and when running with a path to /path/to/demo.py has sys.path=["/path/to", "~/.micropython/lib:/usr/lib/micropython"]
When import mymodule is executed, it's trying to load mp_frozen_stat("/path/to/mymodule"), but the frozen module is just named "mymodule".
I'm not sure if the fix here is to improve the frozen module matching (i.e. assume that all frozen modules are in all sys.paths), or to always have "" as the final entry in sys.path? Or something else? Need to consider how thiss interact with the behavior where filesystem modules override frozen modules of the same name.
This is kind of a feature, in that the location of "" in sys.path allows you to control the order of searching in frozen code. But I think it needs to be improved.
For other people who would like a quick and dirty fix, I 'fixed' the feature by modifying the default sys.path value.
In ports/unix/mponfigport.h I added the following line:
Activity
RobertoRoos commentedon Sep 8, 2020
Is there a quick fix to simply append "" to sys.path whenever micropython starts? Is there an accessible way to run start-up code?
(Hitman1O1 from the forum here)
dpgeorge commentedon Sep 8, 2020
This is kind of a feature, in that the location of
""insys.pathallows you to control the order of searching in frozen code. But I think it needs to be improved.See existing issues: #1804, #2322, #3509
RobertoRoos commentedon Sep 8, 2020
For other people who would like a quick and dirty fix, I 'fixed' the feature by modifying the default sys.path value.
In
ports/unix/mponfigport.hI added the following line:#define MICROPY_PY_SYS_PATH_DEFAULT ":~/.micropython/lib:/usr/lib/micropython"And in
ports/windows/mpconfigport.hI modified the line to look like:#define MICROPY_PY_SYS_PATH_DEFAULT ";~/.micropython/lib"Now
""is always in sys.path. It's actually in there twice when starting the REPL, but I haven't found a consequence of this yet.chrisdecker1201 commentedon Nov 26, 2021
I had/have the same issue.
Quick workaround for me was to just append "" to the sys.path
py: Only search frozen modules when '.frozen' is found in sys.path.
dpgeorge commentedon Dec 17, 2021
Fixed by e0bf461
py: Only search frozen modules when '.frozen' is found in sys.path.
py: Only search frozen modules when '.frozen' is found in sys.path.
py: Only search frozen modules when '.frozen' is found in sys.path.