Closed5
Python-MIP をM1 Mac × dockerで動かす
ピン留めされたアイテム

解決方法
FROM python:3.10.5-buster
...略(pip installなど)
# 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"
...略
ポイント
- slimではなく、busterなどのイメージを使用
- wgetで取得した後、chmodで権限を付与
- 公式に記載されている依存pkgをinstall
- 環境変数を設定
- PMIP_CBC_LIBRARY:
"/usr/local/lib/libCbcSolver.so"
ではなく、"/usr/local/lib/libCbc.so"
- PMIP_CBC_LIBRARY:

このスクラップについて
表題通り。現状のversionだとサポートされていないので動かない。その解決方法をこちらに残す
OS: Mac OS (M1)
image: python:3.10.5-slim
python-mip: 1.14
参考になりそうな情報源

発生している現象
mipを叩くと以下のようなエラーが発生する
...略
name 'cbclib' is not defined
これを解決したい

原因
Using your own CBC binaries (optional)
Python-MIP provides CBC binaries for 64 bits versions of MacOS, Linux and Windows that run on Intel hardware. These binaries may not be suitable for you in some cases:
- macOSにおいて、x86までしかサポートされてないとのこと。
対応方針
- Cbcを入れてみる
- coinbrew:Cbcとその依存関係をダウンロードしてビルドする作業を容易にするスクリプト
- 新しくCbcを入れた場合、環境変数を設定する必要があると書かれているのでそれを設定する
https://python-mip.readthedocs.io/en/latest/install.html#Using your own CBC binaries (optional)

対応ログ: cbc周り
Dockerfile
dependencyが公式に書いてあるのでそれを参考
sudo apt-get install gcc g++ gfortran libgfortran-9-dev liblapack-dev libamd2 libcholmod3 libmetis-dev libsuitesparse-dev libnauty2-dev git
FROM python:3.10.5-slim
...略
# m1対応
RUN apt-get install -y wget bash git build-essential gcc g++ gfortran libgfortran-9-dev 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.dylib"
ENV LD_LIBRARY_PATH="/home/haroldo/prog/lib/"
*build-essential はなくてもいいかも
実行時のエラー
#17 14.88 configure:19699: error: "Cannot check for existence of module lapack without pkgconf"
各所で以下のエラー
#17 14.88 configure:19269: g++ -o conftest -O2 -DNDEBUG conftest.cpp -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm >&5
#17 14.88 /usr/bin/ld: cannot find -lmkl_intel_lp64
#17 14.88 /usr/bin/ld: cannot find -lmkl_sequential
#17 14.88 /usr/bin/ld: cannot find -lmkl_core
#17 14.88 collect2: error: ld returned 1 exit status
#17 14.88 configure:19269: $? = 1
#17 14.88 configure: failed program was:
- makeで「/usr/bin/ld: cannot find」と表示されるときは、-lオプションに続くパッケージ(ここでは「Xi」)に関連するライブラリがインストールされていないことを示している (引用)
- lmk;:Intel math Kernel library(Intel MKL)
#17 14.88 configure:18475: result: no
#17 14.88 configure:18486: checking for g++ options needed to detect all undeclared functions
#17 14.88 configure:18508: g++ -c -O2 -DNDEBUG conftest.cpp >&5
#17 14.88 conftest.cpp: In function 'int main()':
#17 14.88 conftest.cpp:43:8: error: 'strchr' was not declared in this scope
#17 14.88 43 | (void) strchr;
#17 14.88 | ^~~~~~
#17 14.88 conftest.cpp:1:1: note: 'strchr' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
#17 14.88 1 | /* confdefs.h */
#17 14.88 configure:18508: $? = 1
#17 14.88 configure: failed program was:
#17 14.88 configure:18475: result: no
#17 14.88 configure:18475: checking for ieeefp.h
#17 14.88 configure:18475: g++ -c -O2 -DNDEBUG conftest.cpp >&5
#17 14.88 conftest.cpp:67:10: fatal error: ieeefp.h: No such file or directory
#17 14.88 67 | #include <ieeefp.h>
#17 14.88 | ^~~~~~~~~~
#17 14.88 compilation terminated.
#17 14.88 configure:18475: $? = 1
#17 14.88 configure: failed program was:
slim起因な気がするので、image変更
FROM python:3.10.5-buster
apt-get から libgfortran-9-devを削除(not foundなため)
環境変数周りがおかしかったので調整
このスクラップは2023/02/27にクローズされました