CVXPY supports Python 3 on Linux, macOS, and Windows. You can use pip or conda for installation. You may want to isolate your installation in a virtualenv, or a conda environment.
(macOS only) Install the Xcode command line tools.
(optional) Create and activate a virtual environment
pip install cvxpy
Test the installation with
pip install pytest pytest cvxpy/tests
conda is a system for package and environment management.
(Windows only) Download the Visual Studio build tools for Python 3.
Create a new conda environment,
conda create --name cvxpy_env conda activate cvxpy_env
or activate an existing one
conda install -c conda-forge cvxpy
Test the installation with
conda install pytest pytest cvxpy/tests
Install from source¶
We strongly recommend using a fresh virtual environment (virtualenv or conda) when installing CVXPY from source.
CVXPY has the following dependencies:
To test the CVXPY installation, you additionally need pytest.
Clone the official CVXPY git repository, or a newly minted fork of the CVXPY repository.
Navigate to the top-level of the cloned directory.
If you want to use CVXPY with edited source code, runpip install -e .
otherwise, runpip install .
Install with CVXOPT and GLPK support¶
pip install cvxopt
should suffice to get support for both CVXOPT and GLPK.
On other platforms, to install CVXPY and its dependencies with GLPK support, follow these instructions:
Install GLPK. We recommend either installing the latest GLPK from source or using a package manager such as apt-get on Ubuntu and homebrew on OS X.
Install CVXOPT with GLPK bindings.
CVXOPT_BUILD_GLPK=1 CVXOPT_GLPK_LIB_DIR=/path/to/glpk-X.X/lib CVXOPT_GLPK_INC_DIR=/path/to/glpk-X.X/include pip install cvxopt
Follow the standard installation procedure to install CVXPY and its remaining dependencies.
Install with GUROBI support¶
CVXPY supports the GUROBI solver.
Install GUROBI version 7.5.2 or greater such that you can
import gurobipy in Python.
See the GUROBI website for installation instructions.
Install with MOSEK support¶
CVXPY supports the MOSEK solver.
Simply install MOSEK such that you can
import mosek in Python.
See the MOSEK website for installation instructions.
Install with XPRESS support¶
CVXPY supports the FICO Xpress solver.
Simply install XPRESS such that you can
import xpress in Python.
See the Xpress Python documentation pages for installation instructions.
Install with Cbc (Clp, Cgl) support¶
CVXPY supports the Cbc solver (which includes Clp and Cgl) with the help of cylp. Simply install cylp (you will need the Cbc sources which includes Cgl) such you can import this library in Python. See the cylp documentation for installation instructions.
Install with CPLEX support¶
CVXPY supports the CPLEX solver.
Simply install CPLEX such that you can
import cplex in Python.
See the CPLEX website for installation instructions.
Install with SDPT3 support¶
The sdpt3glue package allows you to model problems with CVXPY and solve them with SDPT3.
Install with NAG support¶
CVXPY supports the NAG solver.
Simply install NAG such that you can
import naginterfaces in Python.
See the NAG website for installation instructions.
Install with SCIP support¶
CVXPY supports the SCIP solver.
Simply install SCIP such that you can
from pyscipopt.scip import Model in Python.
See the PySCIPOpt github for installation instructions.
CVXPY’s SCIP interface does not reliably recover dual variables for constraints. If you require dual variables for a continuous problem, you will need to use another solver. We welcome additional contributions to the SCIP interface, to recover dual variables for constraints in continuous problems.
Install with SCIPY support¶
CVXPY supports the SCIPY solver for LPs. This requires the SciPy package in Python which should already be installed as it is a requirement for CVXPY. SciPy’s “interior-point” and “revised-simplex” implementations are written in python and are always available however the main advantage of this solver, is its ability to use the HiGHS LP solvers (which are written in C++) that comes bundled with SciPy version 1.6.1 and higher.