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:
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/Pythondirectory. Copy this extra directory into the first download’s
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
sudo cp bin/osx64/liblpsolve55.a bin/osx64/liblpsolve55.dylib /usr/local/lib(this step courtesy of this blog)
- You now need to edit
setup.py, 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/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/malloc'], ...
You may also want to update the version number (126.96.36.199) in
setup.py, which does not match the originally downloaded files (188.8.131.52); I’m not sure which is correct.
python setup.py build
python setup.py install. This writes out …
/lib/python2.7/site-packages/lpsolve55-184.108.40.206-py2.7.egg-info(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
setup.py file. And I did not find it necessary to copy the
.dylib files anywhere.
If you’re using WebFaction, you will also want to change the final
install command (as described here), to:
python setup.py install --install-lib=$HOME/webapps/web_app/lib/python2.7 \ --install-scripts=$HOME/webapps/web_app/bin \ --install-data=$HOME/webapps/web_app/lib/python2.7
This also worked.
Hope that helps someone out there – let me know if you have any comments.