Frozen modules not present when running external scripts?
-
- Posts: 1
- Joined: Mon Jul 30, 2018 8:37 pm
Frozen modules not present when running external scripts?
I've been experimenting with frozen modules of late...Today I noticed something odd - the frozen modules are accessible just fine from the micropython cli, but if I try to run a script externally with the imports of my frozen modules specified like so "./micropython testscript.py", it says there is no module named my module. But if I just run ./micropython and import it there, it's present. What gives?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Frozen modules not present when running external scripts?
The answer seems to lie in sys.path. At the REPL I get
Frozen modules are imported from '', so they will work. But the following script
run from Bash produces
So I think your code needs to issue
I'm not sure why this difference exists.
Code: Select all
>>> sys.path
['', '/home/adminpete/.micropython/lib', '/usr/lib/micropython']
Code: Select all
import sys
def main():
print(sys.path)
if __name__ == '__main__':
main()
Code: Select all
[adminpete@axolotl]: ~
$ micropython rats5.py
['/home/adminpete', '/home/adminpete/.micropython/lib', '/usr/lib/micropython']
[adminpete@axolotl]: ~
$
Code: Select all
if sys.path[0] != '':
sys.path.insert(0,'')
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.