pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe

2024/10/10 0:27:54

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 <= 2prob += -4*x + ystatus = 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 solvestatus = solver.actualSolve(self, **kwargs)File "C:\Users\rahul.bajaj\AppData\Local\Continuum\Anaconda3\lib\site-packages\pulp\solvers.py", line 346, in actualSolveraise 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.

Answer

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.

https://en.xdnf.cn/q/69958.html

Related Q&A

Django urldecode in template file

is there any way do the urldecode in Django template file? Just opposite to urlencode or escapeI want to convert app%20llc to app llc

Structure accessible by attribute name or index options

I am very new to Python, and trying to figure out how to create an object that has values that are accessible either by attribute name, or by index. For example, the way os.stat() returns a stat_resul…

Loading data from Yahoo! Finance with pandas

I am working my way through Wes McKinneys book Python For Data Analysis and on page 139 under Correlation and Covariance, I am getting an error when I try to run his code to obtain data from Yahoo! Fin…

Run Multiple Instances of ChromeDriver

Using selenium and python I have several tests that need to run in parallel. To avoid using the same browser I added the parameter of using a specific profile directory and user data (see below). The p…

numpy 2d array max/argmax

I have a numpy matrix:>>> A = np.matrix(1 2 3; 5 1 6; 9 4 2) >>> A matrix([[1, 2, 3],[5, 1, 6],[9, 4, 2]])Id like to get the index of the maximum value in each row along with the valu…

How do I add a python script to the startup registry?

Im trying to make my python script run upon startup but I get the error message windowserror access denied, but I should be able to make programs start upon boot because teamviewer ( a third-party prog…

Python: How can I filter a n-nested dict of dicts by leaf value?

Ive got a dict that looks something like this:d = {Food: {Fruit : {Apples : {Golden Del. : [Yellow],Granny Smith : [Green],Fuji : [Red], },Cherries : [Red],Bananas : [Yellow],Grapes …

contour plot - clabel spacing

I have trouble with matplotlib / pyplot / basemap. I plot contour lines (air pressure) on a map. I use clabel to show the value of the contour lines. But the problem is: the padding between the value a…

Class-based view has no attribute .as_view() error

Im following this tutorial, trying to make an API for my Products table.Heres my .views/API/apitest.py view:from my_app.views.API.serializers import ProductSerializer from my_app.models import Product …

Ordering query result by numeric strings in django (postgres backend)

I have a table with a name (varchar) field that only holds numeric string and I want to order my queries by this field. But name fields are being ordered by alphabetically but I want them to be ordered…