Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with pip install in Docker on Mac M1 when using Slim distribution of Python

I have an application I run on Docker which works fine on my older intel-based Mac. However, on the M1 Mac, I get pip install errors when running docker-compose up. e.g

 asyncpg==0.24.0
 error: command 'gcc' failed: No such file or directory

My Dockerfile uses python-slim which has no compiler, so I understand why:

FROM python:3.10-slim

WORKDIR /src
COPY . ./
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

I'd like to stick to the -slim package. What is the best way to make this work on the Mac M1?

Thanks!

like image 431
NK1 Avatar asked Oct 21 '25 19:10

NK1


1 Answers

I had a similar issue and forcing the platform to linux/amd64 fixed it:

FROM --platform=linux/amd64 python:3.10-slim

See known issues:

Not all images are available for ARM64 architecture. You can add --platform linux/amd64 to run an Intel image under emulation.

like image 57
Selcuk Avatar answered Oct 24 '25 09:10

Selcuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!