Looking through the forum it appears that this should be possible but doesn't go into great details of the specifics about how to include your own custom python modules into the binary so that your programs can access them natively. Specifically I'm looking for where in the src tree you would put scripts and what if any build switches need to be thrown to get it to work.
Thanks
Compiling in scripts
Re: Compiling in scripts
If you place python modules into the directory "modules", they will be compiled during the build process and embedded into the binary as frozen bytecode.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Compiling in scripts
@dvrhax it would help us answer your query if you clarified what you are aiming to achieve.
If you put a Python source module in the filesystem you can import it and use it. As @Roberthh explained, you can alternatively precompile the module and "freeze" the resultant bytecode as part of the build. The module can then be used in exactly the same way as if it were in the filesystem. The advantage is that RAM is saved in two ways. Firstly the compiler isn't invoked at runtime. And secondly the bytecode resides in Flash rather than in RAM.
If you put a Python source module in the filesystem you can import it and use it. As @Roberthh explained, you can alternatively precompile the module and "freeze" the resultant bytecode as part of the build. The module can then be used in exactly the same way as if it were in the filesystem. The advantage is that RAM is saved in two ways. Firstly the compiler isn't invoked at runtime. And secondly the bytecode resides in Flash rather than in RAM.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Compiling in scripts
Thanks for the clarification. I was looking to do the latter I have the mysql library that I was looking to use but I didn't want it cluttering up the file system plus I assumed there would be other advantages to having it compiled in. Thanks to the both of you for your help.