I am trying to run a python application using pyomo with cbc solver.
When I run it in a docker container it is giving the following error:
AttributeError: 'numpy.float64' object has no attribute 'polynomial_degree'
I am inclined to believe that it is linked with Python not being able to find the cbc executable.
Here is my Dockerfile file:
FROM python:3.9-slim
WORKDIR /app
COPY . .
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
libglpk-dev \
glpk-utils \
curl \
git \
software-properties-common \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m venv venv \
&& . venv/bin/activate \
&& python3 -m pip install --upgrade pip \
&& pip3 install -r requirements.txt
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \
&& (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /root/.profile \
&& eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" \
&& brew install glpk \
&& brew install ipopt \
&& brew install cbc
ENV PATH="/opt/homebrew/opt/cbc/bin:$PATH"
ENV LDFLAGS="-L/opt/homebrew/opt/cbc/lib"
ENV CPPFLAGS="-I/opt/homebrew/opt/cbc/include"
ENV PKG_CONFIG_PATH="/opt/homebrew/opt/cbc/lib/pkgconfig"
ENV PATH="${PATH}:/app/venv/bin:/home/linuxbrew/.linuxbrew/bin:/usr/local/opt/cbc/bin"
EXPOSE 8501
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
And here is the requirements.txt file:
numpy==1.24.3
pandas==2.0.2
pyomo==6.6.1
streamlit==1.23.1
streamlit-aggrid==0.3.4.post3
Please let me know how to resolve this.
I have tried executing which cbc from the python code and it finds the executable to cbc
I ended up solving this myself.
Notably, there are two things that fixed it, the first being that the virtual environment directory needs to be added at the start of the
PATHenvironment variable instead of at the end of it:Secondly, the
altairpackage was needed in therequirements.txtfile along with some changes to the versions of the existing packages.Here is the fixed
requirements.txtfile:The
LDFLAGS,CPPFLAGSandPKG_CONFIG_PATHenvironment variables don't need to be set in theDockerfile.Also, symbolic links to
cbc,ipoptandglpsolare created byhomebrewinside the directory/home/linuxbrew/.linuxbrew/bin, so we need to add that directory to the path.Here is the fixed
Dockerfile: