【发布时间】:2020-12-14 16:52:59
【问题描述】:
我在尝试使用 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 也无法找到它并使用它。我已经尝试过最简单的方法,即重新启动程序和/或我的计算机、删除所有内容并重新安装,等等。
感谢您的帮助。
【问题讨论】:
标签: python anaconda spyder glpk