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

Name 'cbclib' is not defined #335

Open
erelsgl opened this issue Feb 26, 2023 · 14 comments
Open

Name 'cbclib' is not defined #335

erelsgl opened this issue Feb 26, 2023 · 14 comments
Labels
cbc All items related to cbc help wanted Extra attention is needed

Comments

@erelsgl
Copy link

erelsgl commented Feb 26, 2023

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)
@sebheger
Copy link
Collaborator

sebheger commented Mar 1, 2023

@erelsgl Is it a special problem if version 1.15.0? Because you reported #337 which looks like you get a working version 1.14.0?

@sebheger sebheger added cbc All items related to cbc help wanted Extra attention is needed labels Mar 1, 2023
@erelsgl
Copy link
Author

erelsgl commented Mar 2, 2023

I did it in a different computer, where I have version 1.14.0 and Python 3.10.2. I do not know if the reason is related to MIP version, Python version, or something else.

@rschwarz
Copy link
Contributor

rschwarz commented Mar 2, 2023

The error NameError: name 'cbclib' is not defined is a consequence of the ffi.dlopen(libfile) not working, right? This can have different reasons (file not found, some dependency missing, library incompatible to architecture), so it would be great to have a more specific error message here, but I don't know whether cffi can supply that.

@erelsgl
Copy link
Author

erelsgl commented Mar 2, 2023

I verified that the problem exists also in version 1.14.0.

@kotaishr-ie
Copy link

I guess this is caused by the fact that python-mip 1.15 and CBC 2.10.8 are not compatible.

While python-mip 1.15 requires libCbc.dylib to have Osi_getIntegerTolerance, Cbc 2.10.8 and other recent releases doesn't seem to include this in the interface. However, in the master branch, Osi_getIntegerTolerance is included in the interface.

I guess that we have to use Cbc@master due to compatibility constraints for now.

@DRMacIver
Copy link

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.

@erelsgl
Copy link
Author

erelsgl commented Aug 23, 2023

I still have the same issue, which prevents me from using MIP on Windows 11. Is it possible, at least, to add some work-around to the installation docs?

@pabloazurduy
Copy link
Collaborator

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

@pabloazurduy
Copy link
Collaborator

hey, I managed to find a workaround on a M1 pro MacBook:
create a conda env using x86 arch

CONDA_SUBDIR=osx-64 conda create -n myenvmip python=3.10.10 mip 
conda activate myenvmip

done :), probably is not efficient but, works

@OverLucker
Copy link

OverLucker commented Mar 8, 2024

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.

@tuliotoffolo
Copy link
Contributor

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

@MarcelloCeresini
Copy link

For me it's not working. I have a M2 and I ran pip3 install mip==1.16rc0 but still I got "name 'cbclib' is not defined".

Reason: did not manage to locate a library called '.../env/lib/python3.12/site-packages/mip/libraries/cbc-c-darwin-arm64.dylib'

@nhuet
Copy link

nhuet commented May 23, 2024

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?

@erelsgl
Copy link
Author

erelsgl commented May 23, 2024

I too updated mip to 1.16rc0, and I still get the same error: "NameError: name 'cbclib' is not defined". I am on Windows 11 on an HP machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cbc All items related to cbc help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

10 participants