![](/img/trans.png)
[英]pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe
[英]PulpSolverError: PuLP: Error while trying to execute glpsol in Python 2.7
我通過iPython筆記本和Python 2.7在OS X上運行PuLP
。 glpk
利用安裝brew install homebrew/science/glpk
和紙漿通過安裝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
從命令行也是。
我在Ubuntu中遇到了同樣的錯誤,這解決了它。
make install之后必須發出以下命令:
sudo ldconfig
Ldconfig為最新的共享庫創建必要的鏈接和緩存。
https://lists.gnu.org/archive/html/help-glpk/2013-09/msg00018.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.