pyc files and __pycache__

  • Should I be able to find the pycache and/or the pyc files somewhere on the Pycom device's flash after the py scripts have been executed? I don't think the compile() builtin exists in the Pycom firmware to script the creation of pyc files.

    Goal is to use bytecode versions of the scripts so that the source is not casually viewable on deployed devices. Also want to save some space so updates over LTE use minimal data.

    Should I be trying to find pyc files on the device to use for deployment? Or, I see I can use a cross compiler to create mpy bytecode files, but are these not on the device already and its another step to create them.

  • @panda After modules are imported, the compiled code resides in RAM.

  • @robert-hh I tried your mpy-cross_pycom on windows and it seemed to work just fine. Thanks.

    I'm not interested in embedding any modules into the firmware, but to confirm, you don't know of a way to access a local cache on the Pycom device that might have the compiled versions of the modules after they are imported?


  • @panda You can use mpy-cross on your PC to create bytecode files, extension .mpy, which can be used like the source files. These files reside in the file system.
    Alternatively, if you take the challenge to set up the build system, you can embed these cross-compiled files in the flash, not visible in the file system. The compilation and embedding is part of the build process.
    I use to keep copies of the mpy-cross program here:
    I did not update that for a while, so I have to check whether these programs are still useful. The bytecode structure may have been changed with the last update of the MicroPython engine.

Log in to reply

Pycom on Twitter