You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issue with CBC library in Python-MIP on macOS ARM64 (Apple Silicon) #406
Hi, I’m trying to run a Python script that uses the python-mip library with the CBC solver on a MacBook with an ARM64 (Apple Silicon) chip.
I’ve installed CBC correctly using Homebrew (brew install cbc), and I can verify its availability by running cbc --version in the terminal.
However, when I run my script in Spyder, I get the following error:
An error occurred while loading the CBC library: cannot load library 'cbc-c-darwin-x86-64.dylib'...
mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')
....
NameError: name 'cbclib' is not defined
I checked that my CBC installation is for ARM64 using:
from mip import Model, CBC
model = Model(solver_name=CBC)
Despite these efforts, the issue persists. The script runs fine from the terminal, but in Spyder, I still get the architecture mismatch error.
I would appreciate any suggestions on how to force python-mip to use the correct version of CBC installed via Homebrew or how to resolve this compatibility issue in Spyder.
An error occurred while loading the CBC library: cannot load library '/opt/homebrew/lib/python3.9/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib': dlopen(/opt/homebrew/lib/python3.9/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib, 0x0002): tried: '/opt/homebrew/lib/python3.9/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/python3.9/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib' (no such file), '/opt/homebrew/lib/python3.9/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')). Additionally, ctypes.util.find_library() did not manage to locate a library called '/opt/homebrew/lib/python3.9/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib'
Traceback (most recent call last):
File "/Users/karthik/....py", line 167, in <module>
m = Model()
File "/opt/homebrew/lib/python3.9/site-packages/mip/model.py", line 98, in __init__
import mip.cbc
File "/opt/homebrew/lib/python3.9/site-packages/mip/cbc.py", line 603, in <module>
Osi_getNumCols = cbclib.Osi_getNumCols
NameError: name 'cbclib' is not defined
I was able to invoke the CBC MILP solver by itself. I simply git cloned this repo and used pip install . -- looks like the arm64 library was missing in the installation when I did pip3.9 install mip
Python-MIP doesn't install CBC Library for arm64. The installation guide indicates that PMIP_CBC_LIBRARY can be used to specify a custom library, but the dylib installed via brew install cbcdid not work for me.
I cloned the source from GitHub, built it, and set the full path in the environment variable as follows:
% git clone https://github.com/coin-or/coinbrew.git
% cd coinbrew
% git rev-parse HEADa3777537ea9af3b7ee132cde4aa107e2905b36ca
% ./coinbrew fetch build Cbc@master --no-prompt --prefix=aaaa --tests=none --enable-cbc-parallelInstall completed. If executing any of the installedbinaries results in an error that shared libraries cannotbe found, you may need to - add 'export LD_LIBRARY_PATH=/Users/a/Downloads/a/coinbrew/aaaa/lib' to your ~/.bashrc (Linux) - add 'export DYLD_LIBRARY_PATH=/Users/a/Downloads/a/coinbrew/aaaa/lib' to ~/.bashrc (OS X)
% pip install "cffi>=1.17.1" mip
% PMIP_CBC_LIBRARY="/Users/a/Downloads/a/coinbrew/aaaa/lib/libCbc.dylib" python a.pyWelcome to the CBC MILP Solver Version: devel Build Date: May 5 2025
python-mip uses a version of Cbc that is not officially released so brew install mip probably won't work (as you observed). The workaround suggested [above(https://github.com//issues/406#issuecomment-2785146485) seems like the right one, as it appears there has not been a release since the ARM64 libraries were added. It should be straightforward.
I didn’t realize that python-mip uses a different version—thank you for explaining that to me!
I was able to install the preview version, though I ran into the pitfall that in a fresh Python environment the package didn’t show up in pip list.
It was so easy; it works perfectly for me and, on my first run, may even be faster than the official library.
Thanks a lot!
Activity
iamkarthikbk commentedon Apr 8, 2025
I was facing a similar issue:
I was able to invoke the CBC MILP solver by itself. I simply git cloned this repo and used
pip install .-- looks like the arm64 library was missing in the installation when I didpip3.9 install miparithauth commentedon May 5, 2025
I’ve encountered a similar issue as well.
Python-MIP doesn't install CBC Library for arm64. The installation guide indicates that
PMIP_CBC_LIBRARYcan be used to specify a custom library, but the dylib installed viabrew install cbcdid not work for me.I cloned the source from GitHub, built it, and set the full path in the environment variable as follows:
Alternatively, you can:
However, VSCode lets you set this environment variable conveniently:
{ "terminal.integrated.env.osx": { "PMIP_CBC_LIBRARY": "/Users/a/Downloads/a/coinbrew/aaaa/lib/libCbc.dylib" // "PMIP_CBC_LIBRARY": "${workspaceFolder}/coinbrew/dist/lib/libCbc.dylib" } }tkralphs commentedon May 6, 2025
python-mipuses a version of Cbc that is not officially released sobrew install mipprobably won't work (as you observed). The workaround suggested [above(https://github.com//issues/406#issuecomment-2785146485) seems like the right one, as it appears there has not been a release since the ARM64 libraries were added. It should be straightforward.tkralphs commentedon May 6, 2025
See #367 .
tkralphs commentedon May 6, 2025
Actually, it looks like there is a release candidate you can try that has the ARM64 binaries.
arithauth commentedon May 6, 2025
I didn’t realize that python-mip uses a different version—thank you for explaining that to me!
I was able to install the preview version, though I ran into the pitfall that in a fresh Python environment the package didn’t show up in pip list.
It was so easy; it works perfectly for me and, on my first run, may even be faster than the official library.
Thanks a lot!