尝试在spyder上使用GLPK运行时出错

问题描述

我在尝试使用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也无法找到并使用它。我已经尝试过最简单的操作,例如重新启动程序和/或计算机,擦除所有内容并重新安装,等等。

感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)