Home > Blockchain >  Apple M1 docker tensorflow - ModuleNotFoundError: No module named 'tensorflow'
Apple M1 docker tensorflow - ModuleNotFoundError: No module named 'tensorflow'

Time:07-18

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

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

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 https://tf.kmtea.eu/whl/stable.html
RUN pip install psycopg2-binary --no-binary psycopg2-binary
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY entrypoint.sh /usr/src/entrypoint.sh
ENTRYPOINT ["sh","/usr/src/entrypoint.sh"]
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

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

Here is the error I get:

ModuleNotFoundError: No module named 'tensorflow'

CodePudding user response:

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.

  • Related