Install lpsolve for Python

Today I wanted to try out using lpsolve with the python API on my Mac (OS X 10.7) and on my linux server.

Installing it on the Mac is tricky, but the essence is described in this blog post (here I clarify a few things that stumped me for a while, leave out some of the changes mentioned there that I didn’t need to do, and update a path or two):

  • Search for and download both of:
    • lp_solve_5.5.0.15_source.tar.gz
    • lp_solve_5.5.0.15_Python_source.tar.gz

    e.g. from sourceforge (I originally got a different version of one of these, and it did something quite different).

  • The first will extract to a folder lp_solve_5.5. The second will extract to a folder with the same name, however it will only contain an extra/Python directory. Copy this extra directory into the first download’s lp_solve_5.5 folder.
  • cd into this lp_solve_5.5 directory.
  • cd lpsolve55
  • sh ccc.osx . You will get a lot of warnings, but that’s ok. This will create a bin/ directory. On my Mac it has a subdirectory osx64/, containing liblpsolve55.a and liblpsolve55.dylib.
  • sudo cp bin/osx64/liblpsolve55.a bin/osx64/liblpsolve55.dylib /usr/local/lib (this step courtesy of this blog)
  • cd ../extra/Python
  • You now need to edit, as suggested in the blog post above (here I have updated the included directories to reflect current Xcode practice):
    LPSOLVE55 = '../../lpsolve55/bin/osx64' # not ux32
        ext_modules = ...
            include_dirs = ['../..', '/Applications/', '/Applications/'],

    You may also want to update the version number ( in, which does not match the originally downloaded files (; I’m not sure which is correct.

  • python build
  • python install . This writes out …/lib/python2.7/site-packages/lpsolve55- (in my case into my virtualenv)
  • >>> from lpsolve55 import * should now work in python.

Once this was working, I also installed lpsolve on my linux (CentOS) server. I followed the same steps there, except I executed the straight ccc file rather than ccc.osx (I changed it to refer to ~/tmp instead of /tmp, since I’m using shared hosting and cannot execute from /tmp). On linux there is no need to change the file. And I did not find it necessary to copy the .a or .dylib files anywhere.

If you’re using WebFaction, you will also want to change the final install command (as described here), to:

python install --install-lib=$HOME/webapps/web_app/lib/python2.7 \
  --install-scripts=$HOME/webapps/web_app/bin \

This also worked.

Hope that helps someone out there – let me know if you have any comments.

5 thoughts on “Install lpsolve for Python”

  1. I installed the Python wrapper of lpSolve on my MacOSX that runs Sierra as you suggested. It works but only if the SIP is disabled. Otherwise, Python would respond that it does not allow relative rpaths from to a restricted binary. SIP is a new cybersecurity measure that come w the newest OSX version. Do you have an idea, how to create absolute paths in the build process of

  2. i m having a problem when executing sh ccc on ubuntu
    ccc: 10: ccc: cc: not found
    ccc: 1: ccc: /tmp/platform: Permission denied
    ccc: 40: ccc: cc: not found
    ccc: 41: ccc: ar: not found
    ccc: 42: ccc: ranlib: not found
    ccc: 46: ccc: cc: not found
    ccc: 47: ccc: cc: not found

  3. OMG it finally worked when I followed your instructions step-by-step! I’m a newcomer to all these custom installation stuff, so thanks a bunch for the instructions! God-send :p

Comments are closed.