pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe
Asked Answered
S

5

8

I am a newbie with python and optimization. I am getting some error, please help me resolve it. I tried running the below mentioned code in PyCharm where I am running Anaconda 3

from pulp import *
x = LpVariable("x", 0, 3)
y = LpVariable("y", 0, 1)
prob = LpProblem("myProblem", LpMinimize)

prob += x + y <= 2

prob += -4*x + y

status = prob.solve(GLPK(msg = 0))

value(x)

And I got an error

Traceback (most recent call last): File "D:/Projects/RH Analytics/RNN/TestPulp.py", line 10, in status = prob.solve(GLPK(msg = 0)) File "C:\Users\rahul.bajaj\AppData\Local\Continuum\Anaconda3\lib\site-packages\pulp\pulp.py", line 1643, in solve status = solver.actualSolve(self, **kwargs) File "C:\Users\rahul.bajaj\AppData\Local\Continuum\Anaconda3\lib\site-packages\pulp\solvers.py", line 346, in actualSolve raise PulpSolverError("PuLP: cannot execute "+self.path) pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe

Process finished with exit code 1

So I downloaded the glpk package from here, extracted from the zip file and placed it in a folder in C drive. In the path variable I added "C:\winglpk-4.57\glpk-4.57\w64".

But even now I am getting the same error when i run the program in the PyCharm IDE. Please help me sort out what am I missing.

Sinuation answered 13/1, 2016 at 10:27 Comment(0)
G
6

pulp.pulpTestAll()
When you run this command, a list of tests will run and on 32nd line you see:

Solver pulp.solvers.GLPK_CMD unavailable.

So try and download glpk-utils package then run

glpsol.

It can be done from cmd as well, worked for me.

Gracielagracile answered 2/11, 2016 at 7:1 Comment(1)
I ran the pulp.pulpTestAll() , I get the following output * Solver <class 'pulp.solvers.GLPK_CMD'> passed. but I still get the error PulpSolverError: PuLP: Error while executing glpsol.exeJipijapa
G
3

I had the same issue and I managed to solve it by renaming the variable. When the variable name in the code and the variable name declared in the argument of LpVariable() are not the same, it works, otherwise i get the same error.

x = LpVariable('x', 0, 3)      # This doesn't work
x = LpVariable('x_var', 0, 1)  # This works

I don't know if that is just the case on my machine, since in the documentation they also use the same names for both variables, but it's worth a try.

Garwin answered 30/9, 2020 at 15:1 Comment(0)
C
1

It gives me the same error in Ubuntu. Using the following commands fixed that,

sudo apt-get install python-glpk
sudo apt-get install glpk-utils
Crifasi answered 16/4, 2021 at 8:24 Comment(1)
first package was not found, but installing the second worked for meSantoro
J
0

For me it was the fact that I installed Pulp trough Anaconda (since it's company policy). After uninstalling it trough anaconda prompt and installing it back again trough "pip install pulp" in the normal comand prompt, it was all good

Junette answered 6/4, 2023 at 14:11 Comment(0)
L
-2

After struggling for a while, this solved it for me: set use_mps to False:

prb.solve(use_mps=False)
Lisle answered 15/10, 2020 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.