Pyomo and Gurobi with Anaconda

1,878 views
Skip to first unread message

Hugh Medal

unread,
Aug 31, 2016, 12:02:33 PM8/31/16
to Pyomo Forum
Hello,

I have installed Pyomo with Conda using these instructions:

conda install -c conda-forge pyomo

conda install -c conda-forge pyomo.extras


as well as Gurobi with anaconda using these instructions:

conda config --add channels http://conda.anaconda.org/gurobi
conda install gurobi

However, when I run this code:

from __future__ import division

from pyomo.environ import *


model = ConcreteModel()


model.x = Var([1,2], domain=NonNegativeReals)


model.OBJ = Objective(expr = 2*model.x[1] + 3*model.x[2])


model.Constraint1 = Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)



opt = SolverFactory("gurobi")

instance = model.create_instance()

results = opt.solve(instance)

results.write()


I get this error:


WARNING: DEPRECATION WARNING: Cannot call Model.create_instance() on a

constructed model; returning a clone of the current model instance.

Traceback (most recent call last):

  File "/Users/hm568/git/stochOpt/src/pyomo/testopt.py", line 15, in <module>

    results = opt.solve(instance)

  File "/anaconda/lib/python2.7/site-packages/pyomo/opt/base/solvers.py", line 508, in solve

WARNING: "[base]/site-packages/pyomo/solvers/plugins/solvers/GUROBI.py", 233, _default_executable

Could not locate the 'gurobi' executable, which is required for solver gurobi

    self.available(exception_flag=True)

  File "/anaconda/lib/python2.7/site-packages/pyomo/solvers/plugins/solvers/GUROBI.py", line 139, in available

    val = ILMLicensedSystemCallSolver.available(self, exception_flag)

  File "/anaconda/lib/python2.7/site-packages/pyomo/opt/solver/ilmcmd.py", line 35, in available

    if not pyomo.opt.solver.shellcmd.SystemCallSolver.available(self, exception_flag):

  File "/anaconda/lib/python2.7/site-packages/pyomo/opt/solver/shellcmd.py", line 121, in available

    raise ApplicationError(msg % self.name)

pyutilib.common._exceptions.ApplicationError: No executable found for solver 'gurobi'


Do you have an idea how I can fix this?


Thanks,

Hugh

Santiago rodriguez

unread,
Aug 31, 2016, 12:26:42 PM8/31/16
to Pyomo Forum
Hi,

Pyomo is not able to find your gurobi executable. I tried out your conda-gurobi installation and it seems that the gurobi executable you get in the conda/bin folder is named 'gurobi_cl' and not gurobi, so when you create your solver factory you should call that instead

opt = SolverFactory("gurobi_cl")

That will probably get pyomo to find your gurobi. Do you have a valid gurobi license? If not you need to download it from 


Add the gurobi license to your PATH and then it must probably work fine.

Santiago

instance = model.create_instance() is no longer necessary with concrete models. You can simply do instance = model
Reply all
Reply to author
Forward
0 new messages