gpt4 book ai didi

python - PulpSolverError : PuLP: Error while trying to execute glpsol in Python 2. 7

转载 作者:行者123 更新时间:2023-11-28 17:33:31 28 4
gpt4 key购买 nike

我通过 iPython 笔记本和 Python 2.7 在 OS X 上运行 PuLPglpk 使用 brew install homebrew/science/glpk 安装,PuLP 通过 pip install pulp 安装。

但是我在 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

这是触发此错误的代码:

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))

导致错误的原因是什么,如何修复?

最佳答案

如果你跑

pulp.pulpTestAll()

你可能会看到这样一行:

Solver pulp.solvers.GLPK_CMD unavailable

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

glpsol

同样来自命令行。

关于python - PulpSolverError : PuLP: Error while trying to execute glpsol in Python 2. 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32688324/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com