Registry / data / cvxopt

cvxopt

JSON →
library1.3.3pypypi✓ verified 24d ago

CVXOPT is a Python package for convex optimization. It provides a dense and sparse matrix object type and an extensive library of solvers for linear programs, quadratic programs, semidefinite programs, and general convex optimization problems. The current version is 1.3.3, and it receives active maintenance, primarily through bug fixes and Python version compatibility updates (e.g., Python 3.8+ is generally recommended).

pip install cvxopt
INSTALL
IMPORT
SIG · CVXOPT
C
cvxopt
datapythonv1.3.3
Install
2.1s avg
Import
10ms
Disk
72MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.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
installs and imports cleanly · install 0.0s · import 0.010s · 66.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.1s · import 0.010s · 82MB
72MB installed
● package 72MB
Code
Verified usage

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

matrix
from cvxopt import matrix
import cvxopt.matrix
While 'import cvxopt.matrix' works, importing `matrix` directly is more common for convenience when frequently using the type.
solvers
from cvxopt import solvers
import cvxopt.solvers
Similar to `matrix`, `solvers` is typically imported directly for cleaner access to solver functions like `solvers.lp`.

This example demonstrates how to solve a simple Linear Program (LP) using `cvxopt.solvers.lp`. It sets up the objective function vector `c`, the inequality constraint matrix `G`, and the right-hand side vector `h`, then invokes the solver to find the optimal solution.

from cvxopt import matrix, solvers # Minimize -4x_1 - 5x_2 # Subject to: # x_1 + 2x_2 <= 10 # 3x_1 + 2x_2 <= 12 # x_1 >= 0, x_2 >= 0 # Objective function c (coefficients of x_1, x_2) c = matrix([-4.0, -5.0]) # Inequality constraints Gx <= h # G for x_1 + 2x_2 <= 10 (row 1) # G for 3x_1 + 2x_2 <= 12 (row 2) # G for x_1 >= 0 (i.e., -x_1 <= 0, row 3) # G for x_2 >= 0 (i.e., -x_2 <= 0, row 4) G = matrix([[1.0, 3.0, -1.0, 0.0], [2.0, 2.0, 0.0, -1.0]]) # Note: CVXOPT matrix is column-major h = matrix([10.0, 12.0, 0.0, 0.0]) # Solve the linear program sol = solvers.lp(c, G, h) # Print optimal values print('Optimal solution:') print(f'x_1 = {sol["x"][0]}') print(f'x_2 = {sol["x"][1]}') print(f'Optimal objective value = {sol["primal objective"]}')
Debug
Known issues
gotchaCVXOPT's solvers primarily operate on its own `cvxopt.matrix` objects, which are distinct from NumPy arrays. While `cvxopt.matrix` can be initialized from NumPy arrays, direct use of NumPy arrays in solver inputs will raise type errors.
fix
Always convert NumPy arrays to `cvxopt.matrix` using `matrix(numpy_array)` before passing them to CVXOPT solvers. Be mindful of column-major vs. row-major order when converting.
affects: All versions
gotchaInstallation of CVXOPT, especially on Windows or when seeking high performance, can sometimes be challenging due to its dependency on external BLAS and LAPACK libraries. While `pip install` often works with pre-compiled wheels, custom builds may require careful configuration.
fix
For most users, `pip install cvxopt` should suffice. If experiencing issues or needing optimized performance, consult the official CVXOPT documentation for instructions on linking to specific BLAS/LAPACK implementations (e.g., OpenBLAS, MKL). Consider using a Python distribution like Anaconda, which often bundles optimized numerical libraries.
affects: All versions
gotchaFor very large-scale convex optimization problems or specific problem types, CVXOPT might not offer the same performance or specialized algorithms as commercial solvers (e.g., Gurobi, MOSEK) or other open-source alternatives like CVXPY (which can interface with various backend solvers including CVXOPT).
fix
Benchmark CVXOPT against other solvers for your specific problem scale and type. Consider using `cvxpy` as a modeling layer if you need flexibility to switch between different backend solvers (including CVXOPT) without changing your problem formulation.
affects: All versions
Errors
Common errors & fixes
ImportError: DLL load failed: The specified module could not be found
This error typically occurs on Windows when cvxopt cannot find the necessary underlying C/Fortran libraries (like BLAS, LAPACK, or SuiteSparse) or their associated DLLs, often due to an incomplete installation or incorrect system PATH configuration.
fix
Try installing pre-compiled binary wheels if available for your Python version (e.g., from Christoph Gohlke's repository for Windows), or use a robust package manager like `conda` (`conda install -c conda-forge cvxopt`). If installing via `pip` on Windows, ensure you have the appropriate Visual C++ Build Tools installed and a NumPy version linked against MKL or OpenBLAS.
ModuleNotFoundError: No module named 'cvxopt'
The cvxopt package is not installed in the currently active Python environment, or the Python interpreter running the script is different from the one where cvxopt was installed.
fix
Activate the correct Python virtual environment (if using one) and install cvxopt using `pip install cvxopt`. Verify the installation by running `pip show cvxopt`.
ValueError: Rank(A) < p or Rank([G; A]) < n
This error from cvxopt.solvers indicates that the equality (A) or inequality (G) constraints in the optimization problem are ill-conditioned, inconsistent, or linearly dependent, preventing the solver from determining a unique or feasible solution space. 'p' is the number of equality constraints and 'n' is the number of variables.
fix
Review the mathematical formulation of your optimization problem. Check the rank of your constraint matrices (e.g., using `numpy.linalg.matrix_rank`) to ensure they are independent and that the problem is well-posed. Address any redundancies or inconsistencies in your constraints. Sometimes, scaling the input matrices can also improve numerical stability.
TypeError: 'numpy.ndarray' object is not callable
This error occurs when you attempt to use a NumPy array as if it were a function, typically by using parentheses `()` for indexing instead of square brackets `[]`. This is a common pitfall when switching between NumPy arrays and cvxopt's distinct `matrix` objects, or when confusing array indexing with function calls.
fix
Replace parentheses `()` with square brackets `[]` when attempting to access elements or slice a NumPy array. If you are mixing `cvxopt.matrix` and `numpy.ndarray` objects, ensure you are using the correct syntax for each type, and explicitly convert between them if necessary (e.g., `cvxopt.matrix(numpy_array)` or `numpy.array(cvxopt_matrix)`).
ImportError: /path/to/_cvxopt.so: undefined symbol: dgemm_
The cvxopt C extension (e.g., `_cvxopt.so` on Linux/macOS or `_cvxopt.pyd` on Windows) failed to load because it could not find or link to the required BLAS/LAPACK libraries on your system at runtime.
fix
Install BLAS/LAPACK development libraries (e.g., `sudo apt-get install libblas-dev liblapack-dev` on Ubuntu/Debian, `brew install openblas lapack` on macOS) then reinstall `cvxopt` via `pip install cvxopt`. Alternatively, use `conda install cvxopt`, which typically handles these dependencies automatically.
Upgrade
Version history
1.3.3latest on PyPI · released Feb 9, 2026
Audit
Dependencies
numpyrequiredRequired for numerical operations and data structures underlying cvxopt.matrix.
Agent activity
27 hits · last 30 days
node
20
OpenAI (training)
1
Resources
cvxopt — pip install cvxopt · libregistry