I'm having an error trying to run some python code on spyder with anaconda. Code is very simple:
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)
This is the answer from 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.
Weird thing is, glpsol is installed. When i run glpsol --version
on the terminal I get an answer (v4.65). And if I run which glpsol
I get /Users/Fermin/opt/anaconda3/bin/glpsol
.
So the weird thing is that even though it is installed on my computer (it's a mac), spyder is not being able to find it and use it. I have already tried the simplest of things that is rebooting the programs and/or my computer, erasing everything and installing it again, and some more.
Thanks for the help.
The problem was that I had to install swiglpk.
pip install swiglpk