Installing python-glpk on OS X 10.8

I have been using PuLP for linear optimisation. By default, on OS X, the library used the packaged COIN command line program. This tends to be slow if you are many optimisations as I was doing. Luckily PuLP can handle other optimisers as well like GLPK or paid ones like CPLEX or GUROBI.

So I decided to install GLPK on my computer. This proved harded than I initially imagined.

Installing GLPK Homebrew and swig:

brew install homebrew/science/glpk
brew install swig

Now to install python bindings for GLPK. I tried out two binding for python (more details here):

  • Python-GLPK
  • PyGLPK

I didn’t have any success with PyGLPK. So I stuck with Python-GLPK.

My instructions:

Firstly install ‘ply’

pip install ply

Then download the code and unzip it.

tar xf python-glpk_0.4.43.orig.tar.gz
cd python-glpk-0.4.43/src/

In swig/Makefile replace line number 1 to

PYVERS := 'python2.7'

In folder ‘src’, run


I got these errors and I ignored them.

make -C swig all
swig -python  glpkpi.i
./glpk.h:916: Warning 314: 'in' is a python keyword, renaming to '_in'
sed -i 's/:in /:_in /g'
sed: 1: "": extra characters at the end of g command
make[1]: *** [] Error 1
make: *** [all] Error 2

Now run:

cp swig/ python/
python install

This should install the library. To test if the install worked, go to the examples directory

cd ../examples