I am trying to install qpsolvers using pip. The installation goes without errors, and the module imports properly afterwards.
However, qpsolvers has no available solvers for it to use :
import qpsolvers
print(qpsolvers.available_solvers)
returns []
.
Of course, trying to do anything results in an error:
SolverNotFound: solver 'quadprog' is not available
even on the exemple file for quadprog for instance.
I have checked the location of the package, and it looks like the solvers are there : solver files in the package's solvers folder
Uninstalling and reinstalling or trying older versions didn't work.
How can I fix this?
CodePudding user response:
I install qpsolvers
using pip install qpsolvers
.
the link is here: https://pypi.org/project/qpsolvers/
I run the test code to check it works:
from numpy import array, dot
from qpsolvers import solve_qp
import qpsolvers
M = array([[1., 2., 0.], [-8., 3., 2.], [0., 1., 1.]])
P = dot(M.T, M) # this is a positive definite matrix
q = dot(array([3., 2., 3.]), M).reshape((3,))
G = array([[1., 2., 1.], [2., 0., 1.], [-1., 2., -1.]])
h = array([3., 2., -2.]).reshape((3,))
A = array([1., 1., 1.])
b = array([1.])
x = solve_qp(P, q, G, h, A, b)
print("QP solution: x = {}".format(x))
it produces a result:
QP solution: x = [ 0.30769231 -0.69230769 1.38461538]
I also run the line of code in the question:
print(qpsolvers.available_solvers)
this also produces a result:
['quadprog']
So it all seems fine.
I am using vscode
and windows10
with python3.9
.