Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'cbclib' is not defined #314

Closed
kasperdokter opened this issue Nov 18, 2022 · 2 comments
Closed

NameError: name 'cbclib' is not defined #314

kasperdokter opened this issue Nov 18, 2022 · 2 comments

Comments

@kasperdokter
Copy link
Contributor

kasperdokter commented Nov 18, 2022

I know that others have run into the same exception (NameError: name 'cbclib' is not defined), but my setup is different. My goal is to run the solver in a docker container on 32 bit Raspberry Pi (arm/v6)

First I compiled the solver from source in my container:

# syntax=docker/dockerfile:1
FROM arm32v6/python:3.7-alpine3.15
RUN apk add --no-cache \
    bash \
    gcc \ 
    gfortran \
    git \
    g++ \ 
    libffi-dev \ 
    libgfortran \
    lapack-dev \
    make \
    musl-dev \ 
    patch \
    postgresql-dev \ 
    python3-dev
RUN wget https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
RUN chmod u+x coinbrew
RUN ./coinbrew fetch Cbc@master
RUN ./coinbrew build Cbc@master --prefix=/home/haroldo/prog/ --tests=none --enable-relocatable
ENV PMIP_CBC_LIBRARY="/home/haroldo/prog/lib/libCbcSolver.so"
ENV PATH=$PATH:/home/haroldo/prog/lib
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
RUN chmod u+x ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]

Cross compiling is absolutely necessary, as building CBC on the Raspberry Pi takes more than 12 hours (after which I killed the build).
So I used the following commands on my Windows laptop to compile the above and push it to my docker hub, from where I could pull it to my Raspberry Pi:

docker buildx create --name raspberrypi --platform linux/arm/v6
docker buildx use raspberrypi
docker buildx inspect --bootstrap
docker login
docker buildx build --platform linux/arm/v6 -t kasperdokter/temp . --push

Running the container eventually leads to the following (partial) stack trace:

2022-11-18T09:26:01.562666317Z   File "/core/__init__.py", line 91, in get_pairing
2022-11-18T09:26:01.562837316Z     model = mip.Model()
2022-11-18T09:26:01.563002314Z   File "/usr/local/lib/python3.7/site-packages/mip/model.py", line 98, in __init__
2022-11-18T09:26:01.563173313Z     import mip.cbc
2022-11-18T09:26:01.563341312Z   File "/usr/local/lib/python3.7/site-packages/mip/cbc.py", line 600, in <module>
2022-11-18T09:26:01.563561311Z     Osi_getNumCols = cbclib.Osi_getNumCols
2022-11-18T09:26:01.563730310Z NameError: name 'cbclib' is not defined
  • Operating System & Python, version: arm32v6/python:3.7-alpine3.15
  • Python-MIP version: mip==1.14.1
@kasperdokter
Copy link
Contributor Author

I was able to solve the issue myself, and here is my solution:

The Dockerfile has two problems, and they are caused by improper documentation of Python-MIP
https://docs.python-mip.com/en/latest/install.html.

  1. ENV PMIP_CBC_LIBRARY="/home/haroldo/prog/lib/libCbcSolver.so"
    The solver has been renamed to libCbc.so.
  2. ENV PATH=$PATH:/home/haroldo/prog/lib
    The command line tool is in /home/haroldo/prog/bin, instead of the lib folder.

These small changes fixed my problems.

@Snails8
Copy link

Snails8 commented Feb 27, 2023

Hi there. I had the same problem and handled it in the following way.
I hope this helps anyone else having the same problems,

FROM python:3.10.5-buster

# ....omit (ex) pip install ...)

# deal with m1
RUN apt-get install -y wget bash git gcc g++ gfortran  liblapack-dev libamd2 libcholmod3 libmetis-dev libsuitesparse-dev libnauty2-dev
RUN wget -nH https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
RUN chmod u+x coinbrew
RUN bash coinbrew fetch Cbc@master
RUN bash coinbrew build Cbc@master --no-prompt --prefix=/usr/local --tests=none --enable-cbc-parallel
ENV PMIP_CBC_LIBRARY="/usr/local/lib/libCbc.so"
ENV LD_LIBRARY_PATH="/home/haroldo/prog/lib"

....

points

  • Use images such as buster instead of slim (don't work slim)
  • After obtaining the image with wget, grant permissions by chmod
  • Install the dependency pkg listed officially
  • Set environment variables
    • PMIP_CBC_LIBRARY:"/usr/local/lib/libCbcSolver.so" ではなく、"/usr/local/lib/libCbc.so" 公式だとlibCbcSolver.soになっている

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants