10
$\begingroup$

Note: See the EDIT below for one possible solution.

I apologize if this is not appropriate but I don't really have anywhere else to turn.

I was hoping that someone would be able to post how they would install CPLEX with the Python API. I have tried calling IBM, looking at documentation, YouTube videos, and trying to find examples. Unfortunately, I have had no luck and am unable to install it properly.

If anybody has a simple guide, tutorial, steps, whatever, i'm sure that this would be super helpful to many people down the road.

Edit:

So far I have followed the instructions here and I have installed the CPLEX Optimizer Studio, but when I run "python setup.py install" I get the following: enter image description hereI then tried to set the PYTHONPATH, and that had no impact on my results. My objective is to run the code at the bottom of the link provided above which suggests that the installation would be correct. However, I am unable to run the code completely because I can only get part way until it crashes: enter image description here

EDIT: The entire issue here is that I was running Python 3.7 instead of Python 3.6. Python 3.7 is not available in 64-bit (only 32-bit), but this was overlooked entirely when I first installed Python to begin learning the language. For anybody who finds this and is interested in getting CPLEX up and running, these are the steps I have followed:

  1. Ensure that you are running Python 3.6.x 64-bit. CPLEX will not work on a 32-bit and Python 3.7 is not set up for 64-bit as of yet.

  2. Run pip install cplex

  3. Run pip install docplex

  4. Figure out how to set your "Environment Variable" and create it as PYTHONPATH and then specify the file path for the environment variable in a similar fashion like this: C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\python\3.6\x64_win64

The only downside to this is that each time you want to run CPLEX you need to specify this environment variable it seems, and I am not sure if this will end up causing headaches down the road or not. Unfortunately I was unable to successfully run the script.py, but I found this to work as well.


$\endgroup$
5
  • $\begingroup$ since you apparently tried some steps yourself, it would be helpful to know your platform, environment, what you tried, what you expected, but what happened, maybe logs or output, etc. $\endgroup$ Jul 3, 2019 at 22:51
  • $\begingroup$ What errors do you get? Do you have cplex installed or do you want to use cplex cloud? Assuming you have python installed, maybe you haven't set up the path correctly? A simple search online gives the following links. Check to see if any of them is what you need: ibm; SO; docplex $\endgroup$
    – EhsanK
    Jul 3, 2019 at 22:53
  • $\begingroup$ One alternative I seem to come across is just using PuLP but then it is able to interact with the CPLEX solver? Could interacting with PuLP be a better way of going forward perhaps? $\endgroup$ Jul 3, 2019 at 23:24
  • $\begingroup$ Last year I used CPLEX in my course together with Python, and the experience was so terrible that I switched to Xpress this year. Not sure there really is an elegant way to do it. $\endgroup$
    – Richard
    Jul 4, 2019 at 5:39
  • $\begingroup$ @D.Gray If you are sharing what worked for you, I suggest that you post if after your main question. That way, people can first see the question and then the answer that sort of resolved the issue. $\endgroup$
    – EhsanK
    Jul 4, 2019 at 15:34

3 Answers 3

9
$\begingroup$

It seems there are multiple problems, here...

Python will not automatically find the script setup.py. You need to either specify the path to that script, or be in the directory where that script exists. Assuming that you installed CPLEX Optimization Studio in the default location, the following would work:

python "c:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\python\setup.py" install

Note also that you are using a 32-bit Python environment. And as the warning in the second screenshot tells you, this is not supported. If you have a 32-bit Windows version, CPLEX will definitely not work: it needs a 64 bit operating system.

$\endgroup$
6
  • $\begingroup$ To address your first point: The documentation simply said to run "python setup.py install" in the command line and it didn't work at all, so that was really confusing. I'll give this suggestion a try to see what happens. Second point: I was confused why it was giving me the 32-bit problem. I am using PyCharm and I guess that perhaps it's not a 64 bit version. I didn't think that would have been an issue at first. PyCharm was just the first environment I downloaded when I started learning Python a few weeks ago. $\endgroup$ Jul 4, 2019 at 12:51
  • $\begingroup$ I made an edit addressing this comment. It was quite helpful, however, I was still unable to get the setup.py to function properly so I did a work around with the environment variable instead. $\endgroup$ Jul 4, 2019 at 15:30
  • $\begingroup$ setx variable value should work on Windows to permanently set an environment variable. $\endgroup$ Jul 4, 2019 at 15:34
  • $\begingroup$ I would be happy to try to help further on getting setup.py to execute correctly. It is supposed to... $\endgroup$ Jul 4, 2019 at 15:37
  • $\begingroup$ Okay, I will try to work through this then with you. In my Windows Command Line I input the code that you provided and it runs for a short while but then I get the following at the last line: FileNotFoundError: [Errno 2] No such file or directory: 'dependencies\\python\\certifi-2017.7.27.1.tar.gz $\endgroup$ Jul 4, 2019 at 15:42
2
$\begingroup$

Have you tried this link?

The CPLEX Python API is a Python package named cplex that allows the Callable Library to be accessed from the Python programming language. It is equally suitable for interactive use through the Python interpreter or for writing scripts or full-fledged applications.

$\endgroup$
2
$\begingroup$

Here is the solution that works on me:

  1. open cmd (command prompt)
  2. know where you install ILOG (As for me >> C:\Program Files\IBM\ILOG\CPLEX_Studio129\python)
  3. copy the location
  4. type cd C:\Program Files\IBM\ILOG\CPLEX_Studio129\python
  5. type python "c:/Program Files/IBM/ILOG/CPLEX_Studio129/python/setup.py" install

Note: I don't really sure that the following will help or not, but I also do this on my cmd (it seems that you already do it anyway, just for the passerby):

  1. type pip install cplex
  2. type pip install docplex

Those steps also solve Error can't find certifi-2017.7.27.1.tar.gz

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.