PulpSolverError: PuLP: Error while trying to execute glpsol in Python 2.7

戏子无情 提交于 2019-12-23 16:03:18

问题


I'm running PuLP on OS X via a iPython notebook and Python 2.7. glpk is installed using brew install homebrew/science/glpk and PuLP is installed via pip install pulp.

However I'm getting the error in Python:

---------------------------------------------------------------------------
PulpSolverError                           Traceback (most recent call last)
<ipython-input-15-689fef0dd94f> in <module>()
      1 # Solve the problem
----> 2 status = prob.solve(GLPK(msg=0))
      3 

/Users/x/anaconda/envs/data/lib/python2.7/site-packages/pulp/pulp.pyc in solve(self, solver, **kwargs)
   1641         #time it
   1642         self.solutionTime = -clock()
-> 1643         status = solver.actualSolve(self, **kwargs)
   1644         self.solutionTime += clock()
   1645         self.restoreObjective(wasNone, dummyVar)

/Users/x/anaconda/envs/data/lib/python2.7/site-packages/pulp/solvers.pyc in actualSolve(self, lp)
    364                              stderr = pipe)
    365             if rc:
--> 366                 raise PulpSolverError("PuLP: Error while trying to execute "+self.path)
    367         else:
    368             if os.name != 'nt':

PulpSolverError: PuLP: Error while trying to execute glpsol

Here's the code that triggers this error:

from pulp import *

#Variables
x = LpVariable('x')
y = LpVariable('y')

# Problem
prob = LpProblem('problem', LpMinimize)

# Constraints
prob += x + y <= 1
prob += x <= 1
prob += -2 + y <= 4

# Objective function to minimize
prob += 

# Solve the problem
status = prob.solve(GLPK(msg=0))

What's causing the error, and how can it be fixed?


回答1:


If you run

pulp.pulpTestAll()

you probably will see a line like this:

Solver pulp.solvers.GLPK_CMD unavailable

If so, all you have to do is to install glpk-utils package on your linux. If you succeeded with it, you should be able to call

glpsol

from command line, too.




回答2:


I had the same error in Ubuntu and this solved it.

It is necessary to issue the following command after make install:

sudo ldconfig

Ldconfig creates the necessary links and cache to the most recent shared libraries.

https://lists.gnu.org/archive/html/help-glpk/2013-09/msg00018.html



来源:https://stackoverflow.com/questions/32688324/pulpsolvererror-pulp-error-while-trying-to-execute-glpsol-in-python-2-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!