Registry / ai-ml / osqp
library1.1.3pypypi✓ verified 23d ago

OSQP (Operator Splitting Quadratic Program) is an optimization solver for Quadratic Programs (QPs) using the Alternating Direction Method of Multipliers (ADMM). It's primarily written in C, providing high-level language interfaces for Python, Julia, Matlab, and R. The current Python library version is 1.1.1, with an active development and release cadence of several updates per year, including major versions that introduce breaking changes.

pip install osqp
INSTALL
IMPORT
SIG · OSQP
O
osqp
ai-mlpythonv1.1.3
Install
8.3s avg
Import
1036ms
Disk
233MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 8.3s · import 1.036s · 226MB
233MB installed
● package 233MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

osqp
import osqp
numpy
import numpy as np
sparse
from scipy import sparse

This quickstart demonstrates how to define and solve a simple Quadratic Program using OSQP. It initializes problem matrices (P, A as sparse CSC matrices) and vectors (q, l, u as NumPy arrays), sets up the solver, and then solves the problem, printing the solution status and optimal variable `x`.

import osqp import numpy as np from scipy import sparse # Define problem data P = sparse.csc_matrix([[4, 1], [1, 2]]) q = np.array([1, 1]) A = sparse.csc_matrix([[1, 1], [1, 0], [0, 1]]) l = np.array([1, 0, 0]) u = np.array([1, 0.7, 0.7]) # Create an OSQP object m = osqp.OSQP() # Setup workspace m.setup(P=P, q=q, A=A, l=l, u=u, verbose=False) # Solve problem res = m.solve() # Print results print(f"Problem status: {res.info.status}") print(f"Optimal x: {res.x}")
Debug
Known issues
breakingMigration from v0.6.x to v1.0 introduced significant API changes, including modified `osqp_setup` function signature, new update functions (`osqp_update_data_vec`, `osqp_update_data_mat` replacing old vector/matrix updates), and renamed settings (e.g., `polish` to `polishing`, `warm_start` to `warm_starting`).
fix
Consult the official 'Migration guide from v0.6.x' for a complete list of changes and updated API calls. Update `setup`, `update` method calls, and setting parameters accordingly.
affects: 0.6.x to 1.x
gotchaInstalling optional algebra backends (e.g., `osqp[mkl]` or `osqp[cu12]`) only installs the Python binding; it does NOT automatically install the underlying MKL or CUDA runtime libraries. These libraries must be installed separately and made available to your Python environment for the backends to function.
fix
Ensure MKL or CUDA runtime libraries are correctly installed and configured on your system or within your Python environment (e.g., via `conda install cudatoolkit` or manual installation and `LD_LIBRARY_PATH` setup).
affects: All versions with optional backends
gotchaOSQP is designed for convex Quadratic Programs. While the solver includes heuristics to detect non-convexity, it might fail to reliably identify non-convex problems, especially those with slightly negative eigenvalues of P. Providing non-convex problems can lead to unexpected or incorrect results.
fix
Always verify that your problem formulation results in a convex QP before passing it to OSQP. Consider adding regularization if the convexity is borderline or uncertain.
affects: All versions
gotchaWhen updating problem matrices `P` or `A` using `m.update()`, only the *values* of existing nonzero entries can be changed. Their sparsity pattern (i.e., which entries are zero and non-zero) cannot be modified without a full problem re-setup.
fix
If the sparsity pattern of `P` or `A` needs to change, a new `osqp.OSQP()` object must be created and `m.setup()` called again with the new matrices.
affects: All versions
gotchaBy default, the `problem.solve()` method in v1.x has `raise_error=False`. This means if the solver does not reach an optimal solution (e.g., due to reaching max iterations or being primal/dual infeasible), it will return a result object without raising an exception, potentially hiding issues.
fix
Set `raise_error=True` in `m.solve(raise_error=True)` to explicitly raise an exception if the solver status is not `OSQP_SOLVED`. Alternatively, always check `res.info.status` to inspect the solver's outcome.
affects: 1.0.0 and later
Errors
Common errors & fixes
RuntimeError: CMake must be installed to build qdldl
The OSQP Python package relies on C/C++ components (like QDLDL), which require CMake to be installed and accessible in your system's PATH during installation.
fix
Install CMake on your system. On Ubuntu, use `sudo apt-get install cmake`. On macOS, use `brew install cmake`. On Windows, download and install from the official CMake website, ensuring it's added to your PATH.
ERROR: Command errored out with exit status 1: command: 'python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\...\setup.py'"'"'; __file__='"'"'C:\...\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\...\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.
This generic pip installation error on Windows often indicates missing C++ build tools, specifically 'Microsoft Visual C++ 14.0 or greater', which are required to compile OSQP's C extensions.
fix
Install the 'Build Tools for Visual Studio' from Microsoft's website. During installation, select the 'Desktop development with C++' workload. Ensure your pip is up-to-date: `python -m pip install --upgrade pip`.
AttributeError: module 'osqp' has no attribute 'solve'
This error occurs when attempting to call a top-level `osqp.solve()` function, which does not exist in the standard OSQP Python interface. The solver instance must be created first.
fix
First, create an OSQP solver object, then call its `solve` method. Example: `import osqp; prob = osqp.OSQP(); prob.setup(P, q, A, l, u); results = prob.solve()`.
ValueError: Workspace allocation error!
This error frequently arises when the provided quadratic program is non-convex (i.e., the P matrix is not positive semi-definite), which OSQP is designed to solve only for convex problems. It can also indicate invalid problem data dimensions or values.
fix
Ensure your quadratic program is convex by verifying that the matrix `P` is positive semi-definite. Double-check all input matrices (`P`, `A`) and vectors (`q`, `l`, `u`) for correct dimensions and valid numerical values, especially for `numpy.inf` where appropriate.
ModuleNotFoundError: No module named 'numpy'
This error occurs during the installation of `osqp` when `numpy` is not already installed in the environment, and `osqp`'s `setup.py` attempts to import `numpy` before it's available.
fix
Install `numpy` before attempting to install `osqp`: `pip install numpy` then `pip install osqp`.
Upgrade
Version history
1.1.3latest on PyPI · released Jun 12, 2026
Audit
Dependencies
numpyrequiredRequired for array operations in problem definition.
scipyrequiredRequired for sparse matrix representation of P and A.
Agent activity
17 hits · last 30 days
node
14
Resources
osqp — pip install osqp · libregistry