There are several packages for linear, nonlinear, and quadratic programming in Python. These solvers are typically not written in Python, but provide an interface to a library in a compiled language (C/C++/Fortran).

Linear Programming¶

For linear programming, a few good options are CVXOPT or PuLP. I'll use CVXOPT in these examples because it also provides a quadratic solver. CVXOPT should be included with your Anaconda installation, but if not, you can install it from the command line with pip install cvxopt . (Some people have run into issues installing CVXOPT on Windows. If this happens, you might try these precompiled packages instead).

CVXOPT requires costs and constraints in matrix form:

$$\min_{x} \mathbf{c}^T \mathbf{x}$$$$s.t.: \mathbf{Ax} \leq \mathbf{b}$$

Here is an example problem from the CVXOPT documentation:

$$\min_{x} 2x_1 + x_2$$$$s.t.: -x_1 + x_2 \leq 1$$$$x_1 + x_2 \geq 2$$$$x_2 \geq 0$$$$x_1 - 2x_2 \leq 4$$

After rearranging the constraints to be "less-than", the problem can be solved like this: