Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

CPLEX Installation with Python on CentOS

Following up on this blog entry Free Full version of ILOG Optimization products via IBM's Academic Initiative Program

1. After getting the necessary software and license from IBM Academic Initiative, you should install the CPLEX binary

# ./cplex_studio122.acad.linux-x86.bin

2. For the license file, make use your license file name is "access.ilm" (without the quotation)

3. Create a folder to house the license. CPLEX needs this folder to be present
# mkdir -p /usr/ilog/ilm
# mv access.ilm /usr/ilog/ilm

4. You should be able to run your CPLEX now. To verify, go to the CPLEX binary folder and run it. In my case
# /usr/local/cplex_studio_122/cplex/bin/x86-64_sles10.4.1/cplex

5. To install the Python API of CPLEX, do read up on IBM iLOG Optimization Studio Documentation
# cd /usr/local/cplex_studio_122/cplex/python/x86-64_sles10_4.1/
# python setup.py install --home ./cplex/

You will need to add the path to your PYTHONPATH by running
export PYTHONPATH=$PYTHONPATH:/usr/local/cplex_studio_v12/cplex/python/x86-64_sles10_4.1

Python Error "Could not find platform independent libraries"

I encountered this error after I configure Python.

Could not find platform independent libraries 
Could not find platform dependent libraries
Consider setting $PYTHONHOME to [:]
ImportError: No module named site

Actually, this error can be eliminated once I did a make install. Sometimes, even we system admin forget the simplest thing to do. Sigh

After you untar the python package, do a
# ./configure
# make
# make install

Loading Mod_Python on Apache 2.x on CentOS 4.x and CentOS 5.x

Loading Python on Apache is easy. The material is taken from Mod Python ArchLinux Wiki

Configure Apache
# vim /etc/httpd/conf/httpd.conf

LoadModule python_module modules/mod_python.so

Restart Apache
# service restart httpd

Test Mod_Python
1. Add this block to /etc/httpd/conf/httpd.conf
<Directory /home/www/html> 
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>

2. Create a file in /home/www/html/ called mptest.py and add this as contents

from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.send_http_header()
req.write("Hello World!")
return apache.OK

Restart Apache again
# service restart httpd

Navigate to http://www.yoursite.com/mphandler.py/handler and you should see a site that says
Hello World!