IBM ILOG CPLEX and Python, Nightmare on a Mac!!

Lately, I was playing with CPLEX studio 12, and I found it a nightmare to set it up and running on a Mac OS X with Python. If you like to know how to get rid of the headache, then this topic is for you 🙂

Here is what we do:

1. Get the academic version by applying here:

https://www.ibm.com/developerworks/university/membership/

2. Login to the account and  download CPLEX for Mac from here:

IBM Academic Initiative
More precisely, I had to search for CPLEX in catalog to find it:
IBM Academic Initiative Software Downloads

3. Download the academic license from here:

http://www.ibm.com/developerworks/university/support/ilog.html

4. Install CPLEX binary by running the script from terminal.

5. Rename the license from access.ilm.rdp to access.ilm and copy it into the following folder (create the folder if it doesn’t exists):

/usr/ilog/ilm/

NOTE: Make sure to rename it at this point, CPLEX won’t recognize the downloaded version of the file.

6. Now we can verify to see if CPLEX can run by going to its folder and run  ./cplex.

7. If we have the python installed in Mac (which is usually the case by default), then we can completely import CPLEX libraries and use it in a python program. To do that we go to the following folder:

~/ILOG/CPLEX_Studio_AcademicResearch122/cplex/python/x86_darwin9_gcc4.0

now we need to run the following command to setup the libraries:

8. Once the libraries are setup, we need to add the path to the PYTHONPATH by running the following:

NOTE: you can add the above to your ~/.MacOSX/environment.plist to make it permanent.

9. Not done yet! since the CPLEX python only supports x86 architecture (even though CPLEX itself supports both x86 and x64), and Apple python by defaults run only in x64 mode in snow leopard, so we need to force python to run in x86 mode, and that can be done by:

10. Finally!!! That’s it, now we can run CPLEX code using python and enjoy.

Any question or comments is welcome.

27 thoughts on “IBM ILOG CPLEX and Python, Nightmare on a Mac!!

  1. I am trying to do the same. I noticed there is no “opl” subdirectory in what I have just installed. Does it mean we don’t get the nice “studio” gui in the mac version?

  2. Hi Farshid
    These are great instruction. thanks so much. However, I have a few questions:

    – I dont see the fle access.ilm.rdp. Instead I downloaded the file dlmgr.pro – and renamed it?? do you know if this is right

    – how do I make sure that ampl recognizes the solver cplex and uses it to optimizes

    If you came across any detailed document (PDF), please let me know. thanks. i am still stuck

    any help is appreciated. many thanks.

    • – I’m pretty sure that’s not the right license, better double check that first.
      Update: I just tried again to download the license and it’s still the same access.ilm file, are you sure you have your academic account activated?
      – I haven’t tried with ampl, I take a look at it when there is a chance and let you know.
      – Yes, a pdf document would be great 🙂
      good luck.

  3. Hi Farshid,

    I used to work on Cplex 12.2 through C++2008 on Windows 7.

    I recently moved to Mac. I have downloaded the Mac version of Cplex 12.2. But I cannot install it in Mac even by following what you have said above. The error: “bash#: command not found”.

    And I also tried to install Cplex by installing Windows inside Mac. But in this case I am receiving a very odd error when I want to run Cplex itself ! ” ILOG IBM Cplex in use”.
    And when I run it via C++, it says that “no key found”!

    Can you please help me and let me know how I can cope with them and install Cplex?

    Best
    Mahdi

  4. Thanks.
    I managed to some how install it. to rub Cplex, I clicked on Cplex in “/Users/mahdinoorizadegan/ILOG/CPLEX_Studio_AcademicResearch122/cplex/bin/x86_darwin9_gcc4.0” but it says “license file not found or unreadable” while I have copied “access.ilm” in “ilm” in ILOG directory.

    Also, do you know what is wrong with installing CPLEX in Windows in the way I have installed it? I did the same thing with my friend’s mac and it worked. But his mac is one the old macbook pro mine is the new one! Is there any problem with the new one?

    Cheers
    Mahdi

    • I think running it was simple by just following the instruction in the manual. I don’t use the windows version so I’m afraid I can’t give much help there.
      Good luck!
      /Farshid

  5. when I download cplex from IBM, i get the file in strange format. I tried different tools to extract the file but without success. Any hint please?

  6. Hi,

    I managed to install CPLEX Academic version (although i have to chmod 777 the installation file) in order to run it.

    I followed the steps you have put (which i thank you for them, they are very useful). However, I am not being able to run CPLEX!!

    I went to …./ILOG/CPLEX_Studio_AcademicResearch122/cplex/bin
    where i have two other folders:

    x86-64_darwin9_gcc4.0 and x86_darwin9_gcc4.0 under which there is the cplex executable.

    Running the first one is giving the following error: Bus error
    Running the second one is giving the following error: ./cplex: Bad CPU type in executable

    Any idea?

    Thanks in advance!
    Ahmad

  7. Farshid,

    Great tutorial!!! Thanks a lot. The installation works flawlessly on CPLEX_Studio_AcademicResearch12.3 as well!!

    I’m a newbies, so, after this, can I run the cplex code from IDLE?

    Thanks,

    Choat

  8. Frashid,

    Thanks for the tutorial. I am new to Mac. I have downloaded the licence and put it in the folder usr/ilog/ilm as told. But when trying to follow your instructions and run cplex_studio122.acad.macos.bin from the terminal I get this messabe:
    MacBook-Pro-de-Marta:~ Marta$ Downloads/cplex_studio122.acad.macos.bin
    -bash: Downloads/cplex_studio122.acad.macos.bin: Permission denied

    However, if double click on the file, something happens and a .cpgz is created, but nothing else. Any suggestions??

    Many thanks

    • Hi, you don’t need to open the bin file, you just need to execute it. Just follow the instruction and run it. Once you run the bin file, it will install CPLEX.

  9. Hi Farshid!

    I’m trying install IBM ILOG CPLEX on my mac (lion) following your tutorial but when I try to run the bin file the following message appears:

    -bash: /Users/andrevieira/Documents/cplex_studio124.prev.macos.bin: Permission denied

    Can you help me to solve this?

    Sorry I’m a beginner on Mac…

    Thank you in advance!

    Best regards!

  10. I am successful in installing the cplex 12.4 on my imac with mac OS x lion platform. I am also able to setup libraries in python and the license.

    I am unable to finally use cplex with python. I executed the two commands you have written for environment setting:

    export PYTHONPATH=$PYTHONPATH:~/ILOG/CPLEX_Studio_AcademicResearch122/cplex/python/x86_darwin9_gcc4.0
    export VERSIONER_PYTHON_PREFER_32_BIT=yes

    Can you please instruct me how to add the first one to your ~/.MacOSX/environment.plist to make it permanent.

    When I call ‘import cplex’ in python IDE, it gives a long traceback call. Please instruct me on how to get started with my cplex in python.

  11. Pingback: HOW HANDLE PYTHON ON MAC | Pegahani's blog

  12. Hi Farshid,
    I am caught up in the same nightmare that you’ve been through; except I’m using a linux based operating system (CentOS 7), and I’m trying to use CPLEX inside a virtual environment created using Anaconda. If you could post instructions for linux users as well, that’d be a great help!

    • Hi, sorry I haven’t tried it on Linux but I suspect that the instructions would be very similar to the one on Mac. You can try first and see if anything works differently and let me know here. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *

If you are a bot please fail this test: * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.