2

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?

3 Answers3

1

I met this problem, and finally solved by installing the solver: pip install quadprog, which means that you need to install the solver independently. My python is 3.9 in Windows 10.

樊佳亮
  • 11
  • 1
0

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.

D.L
  • 4,339
  • 5
  • 22
  • 45
  • I did exactly this, and done it again to check, and it doesn't work. I figured it was an issue on my part, but I still have no clue how to fix it. Are the solvers correctly installed on your part ? Trying to run anything from inside the package result in errors with uninstalled modules, even though they seemingly are installed... – user18496484 Mar 17 '22 at 19:02
  • which operating system, ide and python versions do you have? (maybe different python versions can be a problem) I literally just installed this package having never used it before and it worked fine... i would tell you to `pip uninstall qpsolvers`, but you have already done this. does the test code work for you ? – D.L Mar 17 '22 at 19:05
  • Actually, I did not exactly do what you did, I was running this on Spyder. Switched to VS Code and now it works. Guess I'll forever ditch the other one. Thanks a lot! – user18496484 Mar 17 '22 at 19:07
  • you are the second person who has had problems in `spyder` which were solved in `vscode` this evening. glad it works. please mark as accepted as it is useful to other users.... – D.L Mar 17 '22 at 19:10
0

Short answer: pip install qpsolvers[open_source_solvers]

This was indeed a bit confusing: qpsolvers is only an interface, by default it doesn't decide which solvers to install for you (the files from your screenshot in the sub-directory are only interface files, not the solvers themselves).

With newer versions, when the module sees no QP solver at import time, it raises an exception with an advice to install open-source solvers:

>>> import qpsolvers
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  ...
ImportError: no QP solver found, you can install some by running:

    pip install qpsolvers[open_source_solvers]

Hoping this helps!

Tastalian
  • 369
  • 4
  • 12