尝试在 spyder 上使用 GLPK 运行 时出错
Error when trying to run with GLPK on spyder
我在尝试使用 anaconda 运行 spyder 上的某些 python 代码时遇到错误。代码很简单:
import picos
P = picos.Problem()
P.options.verbosity = 1
x = picos.IntegerVariable('x', 2, lower = [0,0])
P.add_constraint(x[0] + x[1] <= 8)
P.set_objective('max', 1*x[0] + 2*x[1])
print(P)
P.solve(solver="glpk")
print(x)
这是spyder的回答
runfile('/Users/Fermin/untitled0.py', wdir='/Users/Fermin')
------------------------------------------
Integer Linear Program
maximize x[0] + 2·x[1]
over
2×1 integer variable x (bounded below)
subject to
x[0] + x[1] ≤ 8
------------------------------------------
===================================
PICOS 2.0
===================================
Problem type: Integer Linear Program.
Searching a solution strategy for GLPK.
Traceback (most recent call last):
File "/Users/Fermin/untitled0.py", line 9, in <module>
P.solve(solver="glpk")
File "/Users/Fermin/opt/anaconda3/lib/python3.8/site-packages/picos/modeling/problem.py", line 1635, in solve
self._strategy = Strategy.from_problem(
File "/Users/Fermin/opt/anaconda3/lib/python3.8/site-packages/picos/modeling/strategy.py", line 187, in from_problem
raise RuntimeError(
RuntimeError: Selected solver GLPK is not available on the system.
奇怪的是,安装了 glpsol。当我 运行 glpsol --version
在终端上时,我得到一个答案 (v4.65)。如果我 运行 which glpsol
我得到 /Users/Fermin/opt/anaconda3/bin/glpsol
.
所以奇怪的是,即使它安装在我的电脑上(它是 mac),spyder 也无法找到并使用它。我已经尝试过最简单的方法,就是重新启动程序 and/or 我的电脑,清除所有内容并重新安装,等等。
感谢您的帮助。
问题是我必须安装 swiglpk。
pip install swiglpk
我在尝试使用 anaconda 运行 spyder 上的某些 python 代码时遇到错误。代码很简单:
import picos
P = picos.Problem()
P.options.verbosity = 1
x = picos.IntegerVariable('x', 2, lower = [0,0])
P.add_constraint(x[0] + x[1] <= 8)
P.set_objective('max', 1*x[0] + 2*x[1])
print(P)
P.solve(solver="glpk")
print(x)
这是spyder的回答
runfile('/Users/Fermin/untitled0.py', wdir='/Users/Fermin')
------------------------------------------
Integer Linear Program
maximize x[0] + 2·x[1]
over
2×1 integer variable x (bounded below)
subject to
x[0] + x[1] ≤ 8
------------------------------------------
===================================
PICOS 2.0
===================================
Problem type: Integer Linear Program.
Searching a solution strategy for GLPK.
Traceback (most recent call last):
File "/Users/Fermin/untitled0.py", line 9, in <module>
P.solve(solver="glpk")
File "/Users/Fermin/opt/anaconda3/lib/python3.8/site-packages/picos/modeling/problem.py", line 1635, in solve
self._strategy = Strategy.from_problem(
File "/Users/Fermin/opt/anaconda3/lib/python3.8/site-packages/picos/modeling/strategy.py", line 187, in from_problem
raise RuntimeError(
RuntimeError: Selected solver GLPK is not available on the system.
奇怪的是,安装了 glpsol。当我 运行 glpsol --version
在终端上时,我得到一个答案 (v4.65)。如果我 运行 which glpsol
我得到 /Users/Fermin/opt/anaconda3/bin/glpsol
.
所以奇怪的是,即使它安装在我的电脑上(它是 mac),spyder 也无法找到并使用它。我已经尝试过最简单的方法,就是重新启动程序 and/or 我的电脑,清除所有内容并重新安装,等等。
感谢您的帮助。
问题是我必须安装 swiglpk。
pip install swiglpk