Apple M1 docker tensorflow – ModuleNotFoundError: No module named 'tensorflow'


I am building a Django app which requires tensorflow and postgres.

I am building it using docker and docker-compose.

Here is my Dockerfile:

FROM --platform=linux/amd64 python:3.9-slim-bullseye


WORKDIR /usr/src/app
RUN python -m pip install --upgrade pip

RUN apt-get update && apt-get install -y --no-install-recommends netcat && \
    apt-get install ffmpeg libsm6 libxext6 build-essential libpq-dev -y &&\
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN pip install tensorflow-aarch64 -f
RUN pip install psycopg2-binary --no-binary psycopg2-binary
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY /usr/src/
ENTRYPOINT ["sh","/usr/src/"]
CMD ["python", "", "runserver", ""]

I do not have Tensorflow nor psycopg2-binary in my requirements.txt

Here is the error I get:

ModuleNotFoundError: No module named ‘tensorflow’


Remove the --platform=linux/amd64, which pulls the x86_64 version of the image. Otherwise, subsequently installing tensorflow-aarch64 would be nonsensical, since your container would not be running natively on the aarch64 architecture and doing import tensorflow in python would, with good reason, fail.

Answered By – One Full Time Equivalent

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published