# Pyomo can't find Gurobi solver

I have a pyomo model that I can solve using the GLPK solver by just using the code:

solver = pyo.SolverFactory('glpk')
solver.options['mipgap'] = 0.02
solution = solver.solve(model, tee=True)


Now I have installed the academic version of Gurobi on my computer. However I can't use Gurobi when having the code:

solver = pyo.SolverFactory('gurobi', solver_io="python")
solver.options['mipgap'] = 0.02
solution = solver.solve(model, tee=True)


I get the error message:

ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin

Now I found this discussion on Stackoverflow Pyomo can't use Gurobi solver I did what the accepted answer advices. I used the windows cmd and navigated to my installation path of Gurobi. I tried two different folders

• C:\Gurobi\win64\
• C:\Gurobi\

and I use the suggested command

python setup.py install


However, I get an error message in the cmd of Windows telling that the command 'python' can't be found or is wrong. Do you know what I have to do in order to use Gurobi with Pyomo in Python?

• Shouldn't it be py3 setup.py install or py -3 setup.py install on Windows?
– joni
Feb 24 at 11:29

The mentioned link is about using gurobipy (gurobi's interface for python) to model your problem and solve it using gurobi. If you want to model the problem using Pyomo and use gurobi as a solver, you need to add the gurobi solver to the system's path. For that do the followings:

1. In Windows search for Edit the system environment variables (I am not familiar with Mac OS).
2. Open Environment Variables
3. In the System variables window click on Path and add the folder that includes your gurobi.exe

then use the following in your code:

solver = pyo.SolverFactory('gurobi')
solver.options['MIPGap'] = 0.02
solution = solver.solve(model, tee=True)

• Thanks Oguz for your comment. Unfortunately, I can't find the gurobi.exe file altough Gurobi has been installed and there is a folder that contains several subfolders Feb 25 at 9:43
• Update: I just adjusted the path variables to the correct Gurobi folder (however, I still can't find any gurobi.exe file). Now when I use your suggested code I get the error message: "ApplicationError: No executable found for solver 'gurobi'" Feb 25 at 9:49
• Any idea why this problem occurs and what I can do? I'd appreciate every further comment Feb 26 at 8:06
• Thanks for your comments and answers. Do you have any idea why Python/Pyomo still can't find the Gurobi solver (see my last update comment)? I'd appreciate any further comments from you. Mar 1 at 9:08
• Thanks Oguz. Now basically it works as intended (I think I just had to restart my laptop to apply all the changes). I really appreciate your great help. I have upvoted and accepted your answer. Mar 1 at 9:55