Soumee Giri
Soumee Giri

Reputation: 59

Installing pandas and pycryptodome dependencies in Dockerfile for python alpine image

I am not able to install pandas and pycryptodome dependencies in the requirements.txt while taking the python:3.8-alpine docker image.

This is the Dockerfile:

FROM python:3.9-alpine
WORKDIR /app
COPY database /app/database
COPY resolvers /app/resolvers
COPY schemas /app/schemas
COPY app.py /app/app.py
COPY requirements.txt /app/requirements.txt
ARG user=user
ARG group=group
ARG uid=6000
ARG gid=6000
RUN apk update 
RUN addgroup -g ${gid} ${group} \
    && adduser -h /app -u ${uid} -G ${group} -s /bin/sh -D ${user}
RUN chown -R user:group /app
RUN pip3 install --upgrade pip
RUN apt-get update 
RUN pip3 install -U --no-cache-dir -r /app/requirements.txt
USER user
EXPOSE 12000
CMD ["python","app.py"]

This is the requirements.txt file:

graphene==2.1.6
Flask-GraphQL==2.0.0
Flask==1.1.1
python-dateutil==2.8.0
pandas==0.24.1
pytz==2018.5
pycryptodome==3.10.1

Ad it's giving the error like:

 ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-_mil4d71/pandas_ce1b9432f9d34cbb838980507a5275a1/setup.py'"'"'; __file__='"'"'/tmp/pip-install-_mil4d71/pandas_ce1b9432f9d34cbb838980507a5275a1/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-mrmagy45
         cwd: /tmp/pip-install-_mil4d71/pandas_ce1b9432f9d34cbb838980507a5275a1/
    Complete output (18 lines):
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 344, in get_provider
        module = sys.modules[moduleOrReq]
    KeyError: 'numpy'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-_mil4d71/pandas_ce1b9432f9d34cbb838980507a5275a1/setup.py", line 732, in <module>
        ext_modules=maybe_cythonize(extensions, compiler_directives=directives),
      File "/tmp/pip-install-_mil4d71/pandas_ce1b9432f9d34cbb838980507a5275a1/setup.py", line 475, in maybe_cythonize
        numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
      File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1130, in resource_filename
        return get_provider(package_or_requirement).get_resource_filename(
      File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 346, in get_provider
        __import__(moduleOrReq)
    ModuleNotFoundError: No module named 'numpy'
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/81/fd/b1f17f7dc914047cd1df9d6813b944ee446973baafe8106e4458bfb68884/pandas-0.24.1.tar.gz#sha256=435821cb2501eabbcee7e83614bd710940dc0cf28b5afbc4bdb816c31cec71af (from https://pypi.org/simple/pandas/) (requires-python:>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement pandas==0.24.1 (from versions: 0.1, 0.2b0, 0.2b1, 0.2, 0.3.0b0, 0.3.0b2, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0rc1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0rc1, 0.8.0rc2, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0rc1, 0.19.0, 0.19.1, 0.19.2, 0.20.0rc1, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0rc1, 0.21.0, 0.21.1, 0.22.0, 0.23.0rc2, 0.23.0, 0.23.1, 0.23.2, 0.23.3, 0.23.4, 0.24.0rc1, 0.24.0, 0.24.1, 0.24.2, 0.25.0rc0, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 1.0.0rc0, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0rc0, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2.0rc0, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4)
ERROR: No matching distribution found for pandas==0.24.1
The command '/bin/sh -c pip3 install -U --no-cache-dir -r /app/requirements.txt' returned a non-zero code: 1

Upvotes: 0

Views: 1286

Answers (2)

fancy
fancy

Reputation: 96

run apk add -U g++ gcc before pip install.

and are you sure apt-get update is ok in alpine?

Upvotes: 0

AKX
AKX

Reputation: 168957

If you don't have an excellent reason to use an Alpine image, don't. (See e.g. Using Alpine can make Python Docker builds 50× slower.)

With e.g. slim-buster you can use prebuilt wheels for Numpy and Pandas.

FROM python:3.9-slim-buster
WORKDIR /app
COPY database /app/database
COPY resolvers /app/resolvers
COPY schemas /app/schemas
COPY app.py /app/app.py
COPY requirements.txt /app/requirements.txt
ARG user=user
ARG group=group
ARG uid=6000
ARG gid=6000
RUN addgroup -g ${gid} ${group} && adduser -h /app -u ${uid} -G ${group} -s /bin/sh -D ${user}
RUN chown -R user:group /app
RUN python -m pip install --upgrade pip setuptools wheel
RUN python -m pip install -U --no-cache-dir -r /app/requirements.txt
USER user
EXPOSE 12000
CMD ["python","app.py"]

Upvotes: 1

Related Questions