Skip to content

How to install gurobi on mac os without conda

Zoltan Tuza edited this page Jan 14, 2021 · 4 revisions

installation

Follow this Link: http://matthiaswalter.org/intpm/Gurobi-Python3-Howto.pdf

cd /Library/gurobi900/mac64
python setup.py install

where 900 is your gurobi version.

test

try out a functional code example in an interactive python session: https://www.gurobi.com/documentation/9.0/examples/qp_py.html

import gurobipy as gp
from gurobipy import GRB

# Create a new model
m = gp.Model("qp")

# Create variables
x = m.addVar(ub=1.0, name="x")
y = m.addVar(ub=1.0, name="y")
z = m.addVar(ub=1.0, name="z")

# Set objective: x^2 + x*y + y^2 + y*z + z^2 + 2 x
obj = x*x + x*y + y*y + y*z + z*z + 2*x
m.setObjective(obj)

# Add constraint: x + 2 y + 3 z <= 4
m.addConstr(x + 2 * y + 3 * z >= 4, "c0")

# Add constraint: x + y >= 1
m.addConstr(x + y >= 1, "c1")

m.optimize()

for v in m.getVars():
    print('%s %g' % (v.varName, v.x))

print('Obj: %g' % obj.getValue())

x.vType = GRB.INTEGER
y.vType = GRB.INTEGER
z.vType = GRB.INTEGER

m.optimize()

for v in m.getVars():
    print('%s %g' % (v.varName, v.x))

print('Obj: %g' % obj.getValue())

If there's no error, gurobi has been successfully installed (Provided that you have a valid gurobi license!)

troubleshooting

On Linux, environmental variables are also needed for bash https://stackoverflow.com/questions/42798173/how-to-resolve-importerror-in-gurobi

Clone this wiki locally