Compile to mpy

The gateway currently supports uploading .mpy file compiled from Python scripts. The specific steps are as follows:

Note

  • A mpy-cross Web version is currently available, which compiles .py code into .mpy file via the web interface.

  • The tool is a static page built with emsdk that runs mpy-cross via WebAssembly and JavaScript. Uploaded scripts are not stored.

System Information

cat /etc/issue
Ubuntu 22.04 LTS \n \l

uname -a
Linux VM-0-9-ubuntu 5.15.0-106-generic

Download Source Code

git clone --branch v1.24.1 --depth 1 https://github.com/micropython/micropython.git
cd micropython/mpy-cross/

Compile and Build

make -j$(nproc)

View Help

./build/mpy-cross -h

# usage: ./build/mpy-cross [<opts>] [-X <implopt>] [--] <input filename>

Prepare the Script

Prepare hello.py with the following content:

echo 'print("hello")' > hello.py

Compile the Script

./build/mpy-cross -o hello.mpy hello.py
ls -lh hello.mpy

# -rw-r--r-- 1 root root 39 Sep  9 18:35 hello.mpy

Upload and Run

After successful execution, the printed output will be visible

OK

hello