Required and optional software
The package requires version 2.7 or 3.x of Python, and is built from source, so the header files and libraries for Python must be installed, as well as the core binaries.
The installation requires BLAS and LAPACK. Using an architecture optimized implementation such as ATLAS, OpenBLAS, or MKL is recommended and gives a large performance improvement over reference implementations of the BLAS and LAPACK libraries.
The installation also requires SuiteSparse. We recommend linking against a shared SuiteSparse library. It is also possible to build the required components of SuiteSparse when building CVXOPT, but this requires the SuiteSparse source which is no longer included with CVXOPT and must be downloaded separately.
The following software libraries are optional.
- The GNU Scientific Library GSL.
- FFTW is a C library for discrete Fourier transforms.
- GLPK is a linear programming package.
- MOSEK version 8 is a commercial library of convex optimization solvers.
- DSDP5.8 is a semidefinite programming solver.
CVXOPT can be installed globally (for all users on a UNIX/Linux system) using the command:
python setup.py install
It can also be installed locally (for a single user) using the command:
python setup.py install --user
It is also possible to install CVXOPT using pip:
pip install cvxopt
To test that the installation was successful, run the included tests using:
python -m unittest discover -s tests
or alternatively, if nose is installed:
If Python does not issue an error message, the installation was successful.
Additional information can be found in the Python documentation.
Customizing the setup script¶
If needed, the default compilation can be customized by editing setup.py or by means of environment variables. The following variables in the setup script can be modified:
BLAS_LIB_DIR: the directory containing the LAPACK and BLAS libraries.
BUILD_GSL: set this variable to 1 if you would like to use the GSL random number generators for constructing random matrices in CVXOPT. If
BULD_GSLis 0, the Python random number generators will be used instead.
GSL_LIB_DIR: the directory containing
GSL_INC_DIR: the directory containing the GSL header files.
BUILD_FFTW: set this variable to 1 to install the
cvxopt.fftwmodule, which is an interface to FFTW.
FFTW_LIB_DIR: the directory containing
FFTW_INC_DIR: the directory containing
BUILD_GLPK: set this variable to 1 to enable support for the linear programming solver GLPK.
GLPK_LIB_DIR: the directory containing
GLPK_INC_DIR: the directory containing
BUILD_DSDP: set this variable to 1 to enable support for the semidefinite programming solver DSDP.
DSDP_LIB_DIR: the directory containing
DSDP_INC_DIR: the directory containing
SUITESPARSE_LIB_DIR: the directory containing SuiteSparse libraries.
SUITESPARSE_INC_DIR: the directory containing SuiteSparse header files.
SUITESPARSE_SRC_DIR: the directory containing SuiteSparse source. The variables
SUITESPARSE_INC_DIRare ignored and relevant parts of SuiteSparse are build from source when
Each of the variables can be overridden by specifying an environment variable
with the prefix
CVXOPT_. For example, the following command installs CVXOPT
CVXOPT_BUILD_FFTW=1 python setup.py install --user
This approach also works with pip:
CVXOPT_BUILD_GLPK=1 CVXOPT_BUILD_FFTW=1 pip install cvxopt
Support for the linear, second-order cone, and quadratic programming solvers in MOSEK is automatically enabled if both MOSEK and its Python interface are installed.
Building CVXOPT from source in Debian/Ubuntu requires the packages
python-dev as well as BLAS and LAPACK library packages
If multiple BLAS and LAPACK libraries have been installed, you can verify the current configuration using the following commands:
update-alternatives --config libblas.so.3 update-alternatives --config liblapack.so.3
Debian Science: Handle different versions of BLAS and LAPACK.
As of Ubuntu 16.04, SuiteSparse can be installed as a dynamic library by
libsuitesparse-dev package. Alternatively, if SuiteSparse is
not available as a dynamic library, the
SuiteSparse source must be available.
To build the optional CVXOPT extensions (DSDP, FFTW, GLPK, and GSL), the following packages should be installed as well:
When all the necessary Ubuntu packages have been installed, CVXOPT can be built with all extensions in Ubuntu 16.04 (or later) as follows:
git clone https://github.com/cvxopt/cvxopt.git cd cvxopt export CVXOPT_BUILD_DSDP=1 # optional export CVXOPT_BUILD_FFTW=1 # optional export CVXOPT_BUILD_GLPK=1 # optional export CVXOPT_BUILD_GSL=1 # optional python setup.py install --user
In older versions of Ubuntu where SuiteSparse is not available as a dynamic
library, the necessary SuiteSparse components can be built with CVXOPT
by downloading the SuiteSparse source and setting
to the SuiteSparse source directory:
wget http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.5.3.tar.gz tar -xf SuiteSparse-4.5.3.tar.gz export CVXOPT_SUITESPARSE_SRC_DIR=$(pwd)/SuiteSparse git clone https://github.com/cvxopt/cvxopt.git cd cvxopt export CVXOPT_BUILD_DSDP=1 # optional export CVXOPT_BUILD_FFTW=1 # optional export CVXOPT_BUILD_GLPK=1 # optional export CVXOPT_BUILD_GSL=1 # optional python setup.py install --user
Building CVXOPT from source in macOS requires the Command-line tools which can be installed using the command:
Homebrew users can build CVXOPT with all extensions as follows:
brew install dsdp gsl fftw homebrew/science/suite-sparse homebrew/science/glpk git clone https://github.com/cvxopt/cvxopt.git cd cvxopt export CVXOPT_BUILD_DSDP=1 # optional export CVXOPT_BUILD_FFTW=1 # optional export CVXOPT_BUILD_GLPK=1 # optional export CVXOPT_BUILD_GSL=1 # optional python setup.py install --user
To use OpenBLAS instead of the built-in BLAS/LAPACK
libraries, include the following commands before running
python setup.py install:
brew install homebrew/science/openblas export CVXOPT_BLAS_LIB_DIR=/usr/local/opt/openblas/lib export CVXOPT_BLAS_LIB=openblas export CVXOPT_LAPACK_LIB=openblas
Alternatively, to use the Intel MKL library include the following commands
python setup.py install:
export CVXOPT_BLAS_EXTRA_LINK_ARGS="-L/opt/intel/lib;-Wl,-rpath,/opt/intel/mkl/lib,-rpath,/opt/intel/lib;-lmkl_core;-lmkl_intel_thread;-liomp5;-lpthread;-lm;-ldl" export CVXOPT_BLAS_LIB_DIR=/opt/intel/mkl/lib export CVXOPT_BLAS_LIB=mkl_intel_lp64 export CVXOPT_LAPACK_LIB=mkl_intel_lp64
If SuiteSparse is not available as a dynamic library, the necessary SuiteSparse
components can be built with CVXOPT by downloading the SuiteSparse source and
CVXOPT_SUITESPARSE_SRC_DIR to the SuiteSparse source directory:
wget http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.5.3.tar.gz tar -xf SuiteSparse-4.5.3.tar.gz export CVXOPT_SUITESPARSE_SRC_DIR=$(pwd)/SuiteSparse git clone https://github.com/cvxopt/cvxopt.git cd cvxopt python setup.py install --user
We will assume that Python 2.7 (64 bit), git, wget, and 7-zip are installed and in the search path. These can be installed with the Chocolatey package manager:
choco install -y wget git python2 7zip.commandline
We will also assume that pip is available;
if it is not, it can now be installed with
Open the Command Prompt and execute the following commands:
rem Download SuiteSparse source wget http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.5.3.tar.gz 7z x SuiteSparse-4.5.3.tar.gz 7z x SuiteSparse-4.5.3.tar set CVXOPT_SUITESPARSE_SRC_DIR=%CD%\SuiteSparse rem Download compatible OpenBLAS library wget https://bitbucket.org/carlkl/mingw-w64-for-python/downloads/OpenBLAS-0.2.17_amd64.7z mkdir openblas 7z x OpenBLAS-0.2.17_amd64.7z -aoa -oopenblas rem Install mingwpy Python extension using pip pip install -i https://pypi.anaconda.org/carlkl/simple mingwpy rem Clone CVXOPT repository, configure, compile, and install git clone https://github.com/cvxopt/cvxopt.git copy openblas\amd64\lib\libopenblaspy.a cvxopt\ cd cvxopt set CVXOPT_BLAS_LIB=openblaspy set CVXOPT_LAPACK_LIB=openblaspy set CVXOPT_BLAS_LIB_DIR=%CD% set CVXOPT_BLAS_EXTRA_LINK_ARGS=-lgfortran;-lquadmath python setup.py build --compiler=mingw32 python setup.py install python -m unittest discover -s tests