Python won't recognize .mpy files

214 views Asked by At

I followed a guide online to compile C code to .mpy files for micropython on the esp32.

I did this by creating a dockerfile to create my work environment:

  FROM ubuntu:23.04

  RUN apt-get update
  RUN apt-get -y install git wget flex bison gperf python3 python3-pip \
      python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util
  RUN apt-get -y install python-is-python3 python3 python3-pip

  RUN pip3 install pyelftools>=0.29

  WORKDIR /src/esp
  RUN git clone -b v4.4.3 --recursive https://github.com/espressif/esp-idf.git
  RUN git clone https://github.com/micropython/micropython.git

  WORKDIR /src/esp/esp-idf
  RUN ./install.sh
  RUN echo "#! /bin/bash\n. /src/esp/esp-idf/export.sh" > esp32_idf
  RUN chown 777 esp32_idf
  RUN chmod +x esp32_idf
  ENV PATH="${PATH}:/src/esp/esp-idf/"

  WORKDIR /src/esp/micropython/mpy-cross
  RUN make
  ENV PATH="${PATH}:/src/esp/micropython/mpy-cross/build/"

  WORKDIR /src/esp/bin
  RUN wget https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1/xtensa-esp32-elf-gcc11_2_0-esp-2022r1-linux-amd64.tar.xz
  RUN tar -xvf xtensa-esp32-elf-gcc11_2_0-esp-2022r1-linux-amd64.tar.xz
  ENV PATH="${PATH}:/src/xtensa-esp32-elf/bin"

  WORKDIR /src/mylib

I then built and ran the image using

docker build -t mpy-lib-builder:t1 .
docker run -it --rm -v "$(pwd)"/lib:/src/mylib mpy-lib-builder:t1 bash

I then copied some files from the micropython examples that can be seen here. I wanteed to use womthing pre-written to test it out. I updated the Makefile to use ARCH = xtensawin (which I am told is the one to use for the esp32 board).

Inside the docker container, I ran the make command, which produced the files:

-lib/
--features0.mpy
--features0.c
--Makefile
--build/
---features0.config.h
---features0.native.mpy
---features0.o

I moved all these files and folder to the root directory of my main application. I then flashed the application to my esp32. When I try to import features0, I get ImportError: no module named 'features0'. Everything else, including other *.py files import just fine. Any ideas what I am doing wrong?

If anyone wants the source code to try it out, just ask and I'll push it to a public repo.

0

There are 0 answers