Module not found issue

Hi, curious if someone could point me in the right direction. I can’t track down the reason I’m seeing a module not found error in my Python script.

The project builds and deploys successfully, but once installed the container errors out with ModuleNotFoundError: No module named 'daiquiri' and reboots continuously.

I’ve used this exact setup in the past, save for the actual python code. Also, as a test, I’ve sent up an empty python script without the requirements installed, ssh’d into the container and manually installed the daiquiri script and ran the script no problem. It seems to be something in the Dockerfile not properly doing the pip install requirements step, but I can’t pinpoint it.

Here’s my setup:

HOST OS VERSION: balenaOS 2.80.5+rev1, production

SUPERVISOR VERSION: 12.8.7

Dockerfile.template

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3-build as build

RUN mkdir /install

WORKDIR /install

COPY requirements.txt /requirements.txt

ENV PATH=/root/.local/bin:$PATH

RUN pip3 install --user -r /requirements.txt

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3-run

COPY --from=build /root/.local /root/.local

ENV PATH=/root/.local/bin:$PATH

RUN install_packages jq iw

WORKDIR /workdir

COPY . .

ENV UDEV=1

CMD ["/bin/sh","./start.sh"]

requirements.txt

pyserial
daiquiri
python-json-logger
schedule

start.sh

#!/bin/bash

set -e

python3 main.py

main.py

from subprocess import Popen, PIPE, STDOUT
import time
import sys
import functools
import logging
import daiquiri
import schedule

rest of python script....

Hey @barryjump, as you are using multi-stage builds, you need to install the libraries in the layer that uses them. In the example you provided, your application is running start.sh which calls main.py. This python file expects to be able to use the daiquiri library (and other libraries you list in your example). But your dockerfile installs this library in your first stage, not in your final stage.

The following line initiates a new layer with new base image:

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3-run

I’d expect that after this line, you would run that pip3 install .. command and install the daiquiri library.

I think you might find these resources helpful:

Let us know how it goes.

Good tip! Managed to get it working by just doing one build stage on the full debian:python, but I’d like to switch back to the multistage so thank you for the help :+1: