Tensorflow not found on pip install inside Docker Container using Mac M1
Asked Answered
C

3

6

I'm trying to run some projects using the new Mac M1. Those projects already work on Intel processor and are used by other developers that use Intel.

I am not able to build this simple Dockerfile:

FROM python:3.9

RUN python -m pip install --upgrade pip

RUN pip install tensorflow==2.6.2

I get this message:

 > [3/3] RUN pip install tensorflow==2.6.2:                                                                                                            
#6 0.583 ERROR: Could not find a version that satisfies the requirement tensorflow==2.6.2 (from versions: none)                                        
#6 0.583 ERROR: No matching distribution found for tensorflow==2.6.2  

I am able to install tensorflow locally, outside of the Dockerfile. Also, friends are able to build this image from their intel Mac.

I even tried to run docker build com different console architectures: i386 and arm64, but none work.

Any suggestions?

Candie answered 2/12, 2021 at 20:24 Comment(0)
S
8

EDIT: you may want to check menrfa's answer by looking at https://github.com/KumaTea/tensorflow-aarch64


The package tensorflow is not available for armv8.

I'll guessing your local python is running using rosetta2 (intel x86_64). You can check that using:

python3 -c "import platform; print(platform.machine())"
x86_64

The solution is forcing Docker to build that image for x86_64 also. It's easy. Just change your Dockerfile to:

FROM --platform=linux/x86_64 python:3.9

RUN python -m pip install --upgrade pip

RUN pip install tensorflow==2.6.2

Or, if you do not want to change your Dockerfile, you may build that image with:

docker build --platform linux/x86_64 -t myimage .

post note:

as [tyrex] said in a comment, although the tensorflow gets installed on the armv8, it will probably fail due to some bugs on the emulation (eg qemu: uncaught target signal 6 (Aborted) - core dumped).

He solved his requirements using PyTorch instead.

Scavenge answered 2/12, 2021 at 21:21 Comment(5)
I tried your solution and it works to install tensorflow, but then I get an error qemu: uncaught target signal 6 (Aborted) - core dumped after import tensorflow . It would be great if you can share how you made it work, please? – Ibex
Hi @tyrex. I've tested only the build. But from your error, it seems qemu is having a hard time running on a different chip. I've seen that behavior on different software, without any success solving it 😞 If you manage to solve it, let me know – Scavenge
Hey @Tiago: Well, my solution was replacing tensorflow with PyTorch :) I was able to get a suitable model from PyTorch and all is good now. – Ibex
Hi @tyrex, thanks for letting us know your solution. I'm going to add a note on my answer. :) – Scavenge
Got the same qeum error in the official tensorflow 2.6.0 docker image – Marquismarquisate
M
6

The following works for me. (Chip Apple M1 Pro + MacOS 12.1)

Docker: Debian GNU/Linux 11 (bullseye)

RUN pip install tensorflow==2.6.0 -f https://tf.kmtea.eu/whl/stable.html

Obviously thanks to https://github.com/KumaTea/tensorflow-aarch64

Marquismarquisate answered 16/2, 2022 at 22:22 Comment(0)
B
0

Tensorflow currently does not provide binaries (.whl files) for linux/arch64 inside docker containers on M1.

But you can use my prebuilt TensorFlow .whl file for M1: https://github.com/diyor28/tf-docker-m1

Beekman answered 20/3, 2022 at 7:37 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.