Search code examples
pythonpyomoglpk

Pyomo using GLPK results in Error - Solver is not found even after applying several solutions


I am trying to solve a linear problem with pyomo (version 6.2). I have already used Gurobi and CPLEX solvers, both worked. Now I am trying to use GLPK, but I an error always pops up.

import pyomo.environ
import pyomo.environ as pyo    

opt = pyo.SolverFactory('glpk', solver_io="python")
results = opt.solve(model, tee=True)

The following error shows up

The SolverFactory was unable to create the solver "_glpk_direct" and returned an UnknownSolver object. This error is raised at the point where the UnknownSolver object was used as if it were valid (by calling method "solve").

The original solver was created with the following parameters:
    executable: _glpk_direct
    type: _glpk_direct
    _args: ()}

I have already checked several solutions. What I have done so far:

  1. I have installed GLPK 4.65 with following instruction: Installing GLPK (GNU Linear Programming Kit) on Windows

  2. Add the glpk executables to the PATH folder. I can run the command "glpsol --help" in the PyCharm terminal and the command prompt

  3. I have installed the glpk package (conda install -c conda-forge glpk)

Still, the current error still pops up and I have not found any other solution to this problem.


Solution

  • After trying other open source solvers like cbc and having the same issue, I have seen that the error with cbc also gives the information:

    ERROR: Unknown IO type: python
    

    Therefore, it simply removed solver_io="python" and it worked out.

    opt = pyo.SolverFactory('glpk')
    

    No clue why this is the case