-1

I cannot figure out why when installing my python dependencies from requirements.txt pip don't complain, but when I do it from docker container, I got the following error message:

The requirements.txt content:

Flask~=1.1
grpcio
grpcio-tools
protobuf
iexfinance
numpy
pandas
pandas_datareader
pymongo

I've created my container like below:

docker run -it -p 8080:50051 -v ${pwd}:/app -w "/app" python:3.8-alpine

I've tried to install my dependencies using this command:

pip install -r requirements.txt

Bellow some screenshot:

enter image description here

enter image description here

Mselmi Ali
  • 1,139
  • 2
  • 18
  • 28
  • Do the suggestions in [this](https://stackoverflow.com/questions/56357794/unable-to-install-grpcio-using-pip-install-grpcio) answer help at all? – Swazy Dec 26 '20 at 21:20
  • 1
    In [pip install fails with "No such file or directory: 'c++': 'c++'"](https://github.com/grpc/grpc/issues/24556) some people recommend to install `gcc-c++`, `python3-devel` or `build-essential`. – Hernán Alarcón Dec 26 '20 at 21:28

2 Answers2

3

Alpine Linux uses musl C, but most python wheel files are compiled for glib C. Therefore, packages that have extensions written in C/C++ need to be compiled. If you do not have a compiler installed, you will get an error.

Instead of installing a compiler and dependencies that packages might require at compile time, I suggest using a python Docker image that is not based on Alpine. For example, you can use python:3.8-slim or python:3.8, and python packages that ship Linux wheels will not have to be compiled. All of the packages listed in OP's requirements.txt can be installed from pre-compiled wheels if using python:3.8-slim.

So you can use these commands

docker run -it -p 8080:50051 -v ${pwd}:/app -w "/app" python:3.8-slim
pip install -r requirements.txt

If you are concerned about the size of the resulting image, you can also use the --no-cache-dir flag in pip install to disable caching.

jkr
  • 17,119
  • 2
  • 42
  • 68
0

The solution was to update alpine-SDK, which is a "meta-package" that pulls in the essential packages used to build new packages."

apk add --update alpine-sdk

I found the solution here:

Github: docker alpine issues

Mselmi Ali
  • 1,139
  • 2
  • 18
  • 28
  • 1
    If you are using alpine for its small size, installing this metapackage defeats that purpose. – jkr Dec 26 '20 at 22:02