Registry / data / cvxpy
library1.9.2pypypi✓ verified 25d ago

CVXPY is a Python-embedded modeling language for convex optimization problems. It allows users to express optimization problems in a natural way that follows mathematical notation, automatically transforming them into standard form, calling a solver, and unpacking the results. It is actively maintained with frequent patch releases, and major versions (e.g., 1.8.x) are supported with bugfixes while the next major release (e.g., 1.9) is under development, with older major versions no longer officially supported.

pip install cvxpy
INSTALL
IMPORT
SIG · CVXPY
C
cvxpy
datapythonv1.9.2
Install
10.5s avg
Import
2976ms
Disk
332MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.7.5 · 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.915 runs
build_error
glibc
py 3.103.915 runs
installs and imports cleanly · install 10.5s · import 2.976s · 289MB
332MB installed
● package 332MB
Code
Verified usage

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

cp
import cvxpy as cp
from cvxpy import *
Importing all symbols with `*` can lead to namespace pollution and make code harder to read and debug. Using `import cvxpy as cp` is the standard and recommended practice.
np
import numpy as np
NumPy is commonly used alongside CVXPY for data generation and manipulation.

This example demonstrates how to solve a least-squares problem with box constraints using CVXPY. It defines variables, an objective function, and constraints, then solves the problem and prints the optimal variable values and duals.

import cvxpy as cp import numpy as np # Problem data. m = 30 n = 20 np.random.seed(1) A = np.random.randn(m, n) b = np.random.randn(m) # Construct the problem. x = cp.Variable(n) objective = cp.Minimize(cp.sum_squares(A @ x - b)) constraints = [0 <= x, x <= 1] prob = cp.Problem(objective, constraints) # The optimal objective value is returned by `prob.solve()`. result = prob.solve() # The optimal value for x is stored in `x.value`. print("Optimal x:\n", x.value) # The optimal Lagrange multiplier for a constraint is stored in # `constraint.dual_value`. print("Dual value for 0 <= x constraint:\n", constraints[0].dual_value)
Debug
Known issues
breakingCVXPY 1.8.0 dropped support for Python 3.10 and NumPy versions older than 2.0.0.
fix
Ensure your Python environment is 3.11 or newer and NumPy is >= 2.0.0. Upgrade with `pip install --upgrade python numpy` if necessary (after updating Python itself).
affects: >=1.8.0
deprecatedCVXPY 1.7 and older major versions are no longer officially supported since the release of CVXPY 1.8.
fix
Upgrade to CVXPY 1.8.x or newer for continued support and bug fixes: `pip install --upgrade cvxpy`.
affects: <1.8.0
gotchaMatrix multiplication behavior changed: `*` is deprecated for matrix-matrix or matrix-vector multiplication. Use `@` for matrix multiplication and dot products. Use `*` for scalar multiplication. For element-wise multiplication, use `cp.multiply`.
fix
Update your code to use the `@` operator for matrix multiplication and `cp.multiply` for element-wise multiplication. Example: `A @ x` instead of `A * x` for matrix-vector product.
affects: >=1.1
gotchaProblems in CVXPY are immutable. If you need to change an objective or constraints (e.g., for parametric programming), you must construct a new `cp.Problem` instance.
fix
Instead of modifying `prob.objective` or `prob.constraints` directly, create a new `cp.Problem(new_objective, new_constraints)`.
affects: All versions
gotchaFor atoms like `cp.sum`, `cp.sum_squares`, `cp.maximum`, `cp.minimum`, always use the CVXPY versions from the `cp` module instead of Python's built-in `sum()`, `max()`, `min()`. The built-in functions do not integrate with CVXPY's modeling language.
fix
Replace Python built-ins with their CVXPY equivalents, e.g., `cp.sum(expr)` instead of `sum(expr)`.
affects: All versions
gotchaCVXPY 1.8 changed the default solver for Mixed-Integer Linear Programs (MILPs) from ECOS_BB (or similar) to HiGHS. If you relied on the behavior or performance of a specific default solver, explicitly specify it using `prob.solve(solver='ECOS_BB')`.
fix
If specific solver behavior is critical, explicitly set the solver parameter: `prob.solve(solver='ECOS_BB')` or `prob.solve(solver='GLPK_MI')`, etc.
affects: >=1.8.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cvxpy'
The cvxpy library is not installed in the currently active Python environment, or the Python interpreter configured in your IDE/terminal is not the one where cvxpy was installed.
fix
Ensure cvxpy is installed using `pip install cvxpy` and its recommended solvers like `pip install ecos osqp scs`. Verify that your development environment is using the correct Python interpreter.
cvxpy.error.DCPError: Problem does not follow DCP rules.
The optimization problem formulation violates the rules of Disciplined Convex Programming (DCP), meaning it is either non-convex or expressed in a way that CVXPY cannot verify as convex. A common specific instance is attempting to multiply two CVXPY variables or non-constant expressions.
fix
Reformulate the objective function or constraints to comply with DCP rules. For example, bilinear terms (product of two variables) are generally not allowed and may require linearization or reformulation if the problem is a Quadratic Program (QP) using specific atoms like `cp.quad_form`.
SolverError: Solver 'xxx' failed. Try another solver.
The chosen numerical solver encountered difficulties (e.g., numerical instability, inability to converge, problem is ill-conditioned, infeasible, or unbounded) or reached its maximum iteration limit.
fix
Try using a different solver (e.g., `prob.solve(solver='ECOS')`, `prob.solve(solver='SCS')`, `prob.solve(solver='CLARABEL')`). Additionally, inspect the problem data for `NaN` values or poor scaling, and use `prob.solve(verbose=True)` to get more detailed output from the solver to diagnose the issue.
ValueError: Problem must be DPP.
The problem, which involves `cvxpy.Parameter` objects, does not conform to Disciplined Parametrized Programming (DPP) rules. DPP compliance is required for efficient re-solving with new parameter values and for automatic differentiation features like `problem.backward()`.
fix
Ensure that the problem is not only DCP-compliant but also adheres to DPP rules. This often means parameters must enter expressions in affine ways or adhere to specific positivity/sign constraints in DGP. If DPP is not strictly needed for performance, you might use `cp.Constant` instead of `cp.Parameter` or manually re-construct the problem.
AttributeError: module 'cvxpy' has no attribute 'Bool'
The `cp.Bool` class was used, which is either deprecated, removed, or never existed in the CVXPY version being used. Boolean variables are now defined differently.
fix
Replace `cvxpy.Bool(shape)` with `cvxpy.Variable(shape, boolean=True)` to declare boolean optimization variables.
Upgrade
Version history
1.9.2latest on PyPI · released Jun 22, 2026
Audit
Dependencies
pythonrequiredRequired runtime environment
numpyrequiredCore array manipulation and mathematical operations
scipyrequiredScientific computing tools, often used in optimization
clarabelrequiredDefault open-source interior-point solver
osqprequiredDefault open-source operator splitting solver
scsrequiredDefault open-source conic solver
highspyrequiredDefault open-source mixed-integer linear programming (MILP) solver
Agent activity
60 hits · last 30 days
node
58
OpenAI (training)
1
Resources
cvxpy — pip install cvxpy · libregistry