google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11.25k stars 2.13k forks source link

Gurobi not found on ubuntu #3843

Closed SanPen closed 1 year ago

SanPen commented 1 year ago

Ortools version: 9.6.2534 (latest as of writing) Language: Python 3.11 Solver: Gurobi 10 OS: Ubuntu 22.04

$_GUROBIHOME = /opt/gurobi (the one containing bin, lib, etc...)

Minimal code:

from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver('GUROBI')

I am getting:

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
W0000 00:00:1688468770.688056   45852 linear_solver.cc:644] Support for GUROBI not linked in, or the license was not found.

info: gurobipy works out of the box

Is this version of gurobi supported?

Is there anything else I should be doing?

Mizux commented 1 year ago

Are you using the 10.0.0 version of gurobi ?

https://github.com/google/or-tools/blob/5425dedcfbb22cb74c636c1374a9b5ad684b1eb5/ortools/gurobi/environment.cc#L318-L324

what is the ouptut of the following command ?

find ${GUROBI_HOME} -type f -iname "*gurobi*.so*"

i.e. where is located libgurobi*.so ?

SanPen commented 1 year ago

Hi,

The output is:

/opt/gurobi/lib/python3.9_utf32/gurobipy.so
/opt/gurobi/lib/python3.11_utf32/gurobipy.so
/opt/gurobi/lib/python3.7/gurobipy.so
/opt/gurobi/lib/libgurobi100_light.so
/opt/gurobi/lib/python3.7_utf32/gurobipy.so
/opt/gurobi/lib/libGurobiJni100.so
/opt/gurobi/lib/python3.10_utf32/gurobipy.so
/opt/gurobi/lib/python3.8_utf32/gurobipy.so
/opt/gurobi/lib/libgurobi.so.10.0.0

So it looks like I have gurobi 10.0.0, plus gurobipy in a couple of places

lperron commented 1 year ago

You can always

from ortools.init import pywrapinit.
pywrapinit.CppBridge.LoadGurobiSharedLibrary('/opt/gurobi/lib/libgurobi.so.10.0.0')

before creating the linear solver.

Note that the API will change in 9.7 to

from ortools.init.python import init
init.CppBridge.load_gurobi_shared_library('/opt/gurobi/lib/libgurobi.so.10.0.0')
SanPen commented 1 year ago

Hi,

thanks.

After a bit of PATH wrangling, I added the following to ~.bashrc:

export GUROBI_HOME="/opt/gurobi"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${GUROBI_HOME}/lib"

where previously I only had:

export GUROBI_HOME="/opt/gurobi"

And now it is detected.