python-mip: Name 'cbclib' is not defined

Describe the bug

I cannot solve even a very simple program, because the system claims that cbclib is not defined:

Traceback (most recent call last):
  File "test_mip.py", line 2, in <module>
    m = Model("test", solver_name=CBC)
  File "local-packages\Python310\site-packages\mip\model.py", line 87, in __init__
    import mip.cbc
  File "local-packages\Python310\site-packages\mip\cbc.py", line 603, in <module>
    Osi_getNumCols = cbclib.Osi_getNumCols
NameError: name 'cbclib' is not defined

To Reproduce

from mip import Model, CBC
m = Model("test", solver_name=CBC)

Expected behavior No error.

Desktop (please complete the following information):

  • Windows 11 22H2
  • Python version: 3.10.10
  • Python-MIP version (we recommend you to test with the latest version): 1.15.0 (also exists in 1.14.0)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 21 (3 by maintainers)

Most upvoted comments

Python-MIP’s latest release candidate version (1.16rc0) includes binaries compatible with M1/M2/M3 processors. To install it, you can use pip:

  • pip3 install mip==1.16rc0

The fix pip3 install mip==1.16rc0 was working before on macos-latest github runners, but not anymore since the release of the new image: https://github.com/actions/runner-images/releases/tag/macos-14-arm64%2F20240514.3 Have you an idea what has changed in the runner (see above link) that could explained this?

I think my problem is related to this topic

I use M1 pro MacBook. Stack trace:

An error occurred while loading the CBC library:         cannot load library '/some/path/lib/python3.11/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib': dlopen(/some/path/lib/python3.11/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib, 0x0002): tried: '/opt/homebrew/opt/mysql@5.7/lib//cbc-c-darwin-x86-64.dylib' (no such file), /some/path/lib/python3.11/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/some/path/lib/python3.11/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib' (no such file), '/some/path/lib/python3.11/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/some/path/lib/python3.11/site-packages/mip/libraries/cbc-c-darwin-x86-64.dylib'

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/some/path/lib/python3.11/site-packages/mip/model.py", line 98, in __init__
    import mip.cbc
  File "/some/path/lib/python3.11/site-packages/mip/cbc.py", line 603, in <module>
    Osi_getNumCols = cbclib.Osi_getNumCols
                     ^^^^^^
NameError: name 'cbclib' is not defined

Key problem is the warning message at the start: mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')),

Look at lib/python3.11/site-packages/mip/libraries directory. image

There is no macos m1 distribution.

Compile it manually via coinbrew. Swap cbc-c-darwin-x86-64.dylib with own compiled file.

It works! 🎆

I think you should add precompiled binary for macos m1.

hey, has anyone found a workaround for this issue? 🙏 thaaanks

I think there are two slightly distinct things here:

  1. Compatibility with different CbC problems (genuine problem, solution is currently to use master as you say)
  2. The error you get when you run into (1) is very confusing, as the code designed to handle this path doesn’t work correctly.

The cbc module actually goes to some work to check for such an error and set a has_cbc flag if it fails. The problem is that code further down the file then goes on to unconditionally use cbclib.

It seems like this means the error handling here ends up the worst of both worlds and either all of the code in this module other than the initial loading should exist in a has_cbc block, or the error from loading cbclib should just be left to propagate.