Registry / data / ecos
library2.0.14pypypi✓ verified 23d ago

ECOS is a lightweight numerical solver for convex second-order cone programs (SOCPs) designed for embedded systems. This library provides its Python interface. It is actively maintained, with version 2.0.14 released in June 2024, and receives regular updates to its Python wrapper.

pip install ecos
INSTALL
IMPORT
SIG · ECOS
E
ecos
datapythonv2.0.14
Install
7.3s avg
Import
950ms
Disk
227MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.14 · 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
glibc
py 3.10
✕ build_error
✓ 6.9s
py 3.11
✕ build_error
✓ 7.2s
py 3.12
✕ build_error
✓ 7.2s
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 8.1s
227MB installed
● package 227MB
Code
Verified usage

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

ecos
import ecos

This example demonstrates how to solve a basic Linear Program (a special case of SOCP) using `ecos.solve`. It minimizes `x[0] + x[1]` subject to non-negativity and a lower bound constraint.

import numpy as np from scipy import sparse import ecos # Define a simple Linear Program (LP) as an SOCP # Minimize: x[0] + x[1] # Subject to: x[0] >= 0, x[1] >= 0, x[0] + x[1] >= 1 # Objective vector c: Minimize x[0] + x[1] c = np.array([1., 1.]) # Inequality constraints Gx <= h (linear cone part) # -x[0] <= 0 # -x[1] <= 0 # -x[0] - x[1] <= -1 (equivalent to x[0] + x[1] >= 1) G = sparse.csr_matrix([ [-1., 0.], [0., -1.], [-1., -1.] ]) h = np.array([0., 0., -1.]) # Dimensions of the cones dims = { 'l': 3, # Number of linear inequality constraints 'q': [], # List of second-order cone dimensions 'e': 0 # Number of exponential cone constraints } # Solve the problem solution = ecos.solve(c, G, h, dims) # Print the optimal solution print(f"Optimal x: {solution['x']}") print(f"Optimal value: {solution['info']['pcost']}")
Debug
Known issues
breakingStarting with version 2.0.8, the `ecos-python` wrapper officially dropped support for Python 2.7. Users on older Python versions must upgrade to Python 3 or use an older `ecos` version.
fix
Upgrade your Python environment to Python 3.x.
affects: >=2.0.8
gotchaThe 2.0.7 release had issues with version syncing, leading to its removal and re-upload as a post-release (e.g., `2.0.7.post1`). Strict dependency pinning to `2.0.7` might fail.
fix
If pinning, use `ecos>=2.0.7` or explicitly `ecos==2.0.7.post1`. It's generally safer to use the latest stable release.
affects: 2.0.7
gotchaInstalling `ecos` from source on Windows can be challenging due to compiler requirements, especially for older Python versions. The official documentation suggests using Miniconda to minimize pain.
fix
Prefer `pip install ecos` to use pre-built wheels. If building from source on Windows, use Miniconda or ensure you have the correct Visual Studio compiler matching your Python version.
affects: All versions, specifically Windows source installs
gotchaThe `CVXPY` library, which often uses ECOS as a solver, changed its default solver from ECOS to Clarabel in version 1.5 and plans to remove ECOS as a default dependency in 1.6. Users relying on ECOS via CVXPY should be aware.
fix
When using `CVXPY`, explicitly specify `solver=cvxpy.ECOS` in `prob.solve()`. Ensure `ecos` is installed in your environment if it's no longer a default dependency of `CVXPY`.
affects: CVXPY >= 1.5
gotchaThe `ecos.solve` function expects sparse matrices `G` and `A` to be in `scipy.sparse.csr_matrix` format. While it attempts to convert other formats, providing them in CSR format is more efficient and avoids potential conversion overhead or unexpected behavior.
fix
Ensure that your `G` and `A` sparse matrices are created as `scipy.sparse.csr_matrix` instances (e.g., `from scipy import sparse; G = sparse.csr_matrix(...)`).
affects: All versions
Errors
Common errors & fixes
Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools"
Installing `ecos` from source on Windows often requires specific Microsoft Visual C++ build tools that are not installed or are an incompatible version with the Python environment.
fix
Install the correct version of Microsoft Visual C++ Build Tools (e.g., from visualstudio.microsoft.com/downloads/#build-tools) matching your Python version, or try installing a pre-compiled wheel for `ecos` if available (e.g., from unofficial Windows binaries websites if `pip` fails to find one).
ModuleNotFoundError: No module named 'numpy'
This error occurs during the installation of `ecos` (e.g., via `pip install ecos`) because its `setup.py` script attempts to import `numpy` before `numpy` has been fully installed as a dependency.
fix
Ensure `numpy` and `scipy` are installed before attempting to install `ecos` by running `pip install numpy scipy` first.
SolverError: Solver 'ECOS' failed.
This error typically indicates that the ECOS solver, often called through a modeling framework like CVXPY, failed to converge to a solution within the specified tolerances or maximum iterations. This can be due to numerical instability, ill-conditioned data, or an infeasible/unbounded problem formulation.
fix
Try rescaling your problem data so values have similar magnitudes, adjust solver parameters like `feastol`, `abstol`, `reltol` (tolerances), or increase `max_iters`. Also, ensure your problem is well-posed (feasible and bounded).
AttributeError: module 'ecos' has no attribute 'solve'
This error happens when attempting to call a method named 'solve' directly on the 'ecos' module itself, instead of using the primary solver function provided by the library, which is also typically named `solve` but is directly callable from the imported module.
fix
After `import ecos`, the main solving function is `ecos.solve()`. Call it directly with your problem parameters, e.g., `solution = ecos.solve(c, G, h, dims)`.
Upgrade
Version history
2.0.14latest on PyPI · released Jun 18, 2024
Audit
Dependencies
numpyrequiredRequired for numerical arrays (vectors/matrices) used as input.
scipyrequiredRequired for sparse matrix representation of constraints.
Agent activity
16 hits · last 30 days
node
14
Meta
1
Resources
ecos — pip install ecos · libregistry