本文介绍了PulpSolverError:PuLP:尝试在 Python 2.7 中执行 glpsol 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 iPython notebook 和 Python 2.7 在 OS X 上运行 PuLP.glpk 使用 brew install homebrew/science/glpk 安装,PuLP 使用 pip install paste 安装.

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.

但是我在 Python 中遇到错误:

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?

推荐答案

如果你运行

pulp.pulpTestAll()

你可能会看到这样的一行:

you probably will see a line like this:

Solver pulp.solvers.GLPK_CMD unavailable

如果是这样,你所要做的就是在你的 linux 上安装 glpk-utils 包.如果你成功了,你应该可以调用

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

也来自命令行.

这篇关于PulpSolverError:PuLP:尝试在 Python 2.7 中执行 glpsol 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 17:53