1

I've been trying to get a docker file running for three days now, but keep failing to install pandas.

Here you can see my Dockerfile:

# pull official base image
FROM python:3.6.5-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apk update
RUN apk add postgresql-dev cargo gcc python3-dev libffi-dev musl-dev zlib-dev jpeg-dev #--(5.2)

COPY . /usr/src/app/
# install dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

And my requirement.txt is:

wheel==0.36.2
asgiref==3.2.10
backcall==0.2.0
beautifulsoup4==4.9.1
certifi==2020.6.20
chardet==3.0.4
colorama==0.4.3
Cython==0.29.22
decorator==4.4.2
defusedxml==0.6.0
Django==3.1.6
django-allauth==0.42.0
django-crispy-forms==1.9.2
django-extensions==3.0.9
django-markdownx==3.0.1
et-xmlfile==1.0.1
gunicorn==20.0.4
idna==2.10
importlib-metadata==2.0.0
ipython
ipython-genutils==0.2.0
jdcal==1.4.1
jedi==0.17.2
Markdown==3.2.2
numpy
oauthlib==3.1.0
openpyxl==3.0.6
parso==0.7.1
pickleshare==0.7.5
Pillow==7.2.0
prompt-toolkit==3.0.7
psycopg2==2.8.6
pycparser==2.20
Pygments==2.7.1
python-dateutil==2.8.1
python3-openid==3.2.0
pytz==2020.1
requests==2.24.0
requests-oauthlib==1.3.0
semantic-version==2.8.5
setuptools-rust==0.11.6
six==1.15.0
soupsieve==2.0.1
sqlparse==0.3.1
toml==0.10.2
traitlets
urllib3==1.25.10
wcwidth==0.2.5
zipp==3.2.0

I'm trying python 3.6.5, 3.7, 3.8, 3.8.5 but it can't install pandas Requirement already satisfied but the wheel says:

gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -DNPY_NO_DEPRECATED_API=0 -Ipandas/_libs/window -I./pandas/_libs -I/tmp/pip-build-env-e3sdep4m/overlay/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include/python3.7m -c pandas/_libs/window/aggregations.cpp -o build/temp.linux-x86_64-3.7/pandas/_libs/window/aggregations.o

  gcc: fatal error: cannot execute 'cc1plus': execvp: No such file or directory
command gcc failed with exit status 1
"failed building wheel for pandas 
pep517 err

So I use:

pip install --no-use-pep517 pandas

But it is not working same error is shown.

How can I install pandas in Python?

2 Answers 2

5

You need g++ in order to go through this.

Try to update the install command in your Dockerfile:

RUN apk add g++ postgresql-dev cargo gcc python3-dev libffi-dev musl-dev zlib-dev jpeg-dev
Sign up to request clarification or add additional context in comments.

2 Comments

i cant believe it I suffered for 3 days because of this.. thanks
@monett Great! Please don't forget to accept this answer.
0

This dockerfile worked for me, maybe you'll need to adjust the version of pandas or python that adjust to your case.In this example I'm using pandas==1.2.4

FROM python:3.9-buster

# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set the working directory in the container
WORKDIR /app

# Install any necessary dependencies
RUN apt-get update && \
    apt-get install -y zip && \
    rm -rf /var/lib/apt/lists/*

# Copy the requirements file to the working directory
COPY requirements.txt .

# Install the Python packages listed in requirements.txt
RUN pip install -r requirements.txt

CMD "Run whatever you'd like"

Requirements.txt file.

pandas==1.2.4

Run docker build.

docker build -t image_name .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.