donut
donut

Reputation: 636

No executable found for solver 'glpk' on pyomo

I have an optimization model written on pyomo (Python 3.7/Ubuntu 18.04) and using

from pyomo.opt import SolverFactory
opt = SolverFactory("gurobi")
results = opt.solve(model)

It works exactly as it should. However, when I try to use glpk as the solver, I get the following error:

ApplicationError: No executable found for solver 'glpk'. 

Importing the package also returns an error:

ModuleNotFoundError: No module named 'glpk'

But when I do conda list on the terminal, I get this information for glpk package:

glpk                      4.65              he80fd80_1002    conda-forge

How can I fix this?

Upvotes: 0

Views: 6941

Answers (2)

Gr3at
Gr3at

Reputation: 492

It's been quite some time, but this might help future users with the same issue.

I had the same issue, while trying to run pyomo along with glpk as a solver on a debian based container image.

I was getting the following error: Could not locate the 'glpsol' executable, which is required for solver 'glpk'. ApplicationError: No executable found for solver 'glpk'.

After installing glpk-utils along with glpk, my python script executed successfully.

part of my working docker file can be found below

FROM python:3.10-slim-bullseye

WORKDIR /opt/app
RUN apt update && apt install -y gcc libglpk-dev glpk-utils
COPY requirements.txt /opt/app/requirements.txt
RUN pip install --upgrade pip && pip install -r requirements.txt
# requirements.txt contents (Pyomo==6.4.2 and glpk==0.4.6 among others)

COPY . .
# utilizing .dockerignore to leave files/folders out of the container image

CMD [ "python", "main.py" ]

Upvotes: 1

EJay
EJay

Reputation: 161

On terminal, trying running which glpsol.

This ought to return a path to your glpsol executable. I am guessing you won't get a result. If that's the case you need to add the location of 'glpsol' to your PATH variable. You should be able to find it by seaching for where the 'glpk' package was installed. It should be in the 'bin' folder. Hopefully.

Upvotes: 0

Related Questions