Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Python DOCplex: Cannot find dll on Windows

    Posted Wed February 20, 2019 11:27 PM

    Originally posted by: WJvanHoeve


    Hello,

    After trying for several days, I am still struggling with getting my Python DOCplex interface up and running.

    Specs:  Windows 8.1 Pro; Python3.6.4; CPLEX 12.8

     

    I installed CPLEX Studio 12.8, and followed the steps to run setup.py as described here:

    https://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.0/ilog.odms.cplex.help/CPLEX/GettingStarted/topics/set_up/Python_setup.html

    When I run a model, for example diet.py in the examples, the model is compiled well, but unable to solve.  The error message is "CPLEX DLL not found".

    Apparently Python does not know where to find the cplex dll, and neither do I...

    (I attempted to define the proper PYTHONPATH variable, but without success so far.)

    Some additional information:

    - The documentation states that I can "set the environment variable PYTHONPATH to yourCPLEXhome/python/PLATFORM".  However, there is no directory indicating a platform under my CPLEX python directory.

    - The diet.py example file states that my PYTHONPATH variable is used to search for cplex_config.py.  I was unable to locate this file on my machine.

     

    If anyone can offer any help, that would be much appreciated.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Python DOCplex: Cannot find dll on Windows

    Posted Thu February 21, 2019 01:32 AM

    In your CPLEX installation there should be a folder cplex/python/2.7/x64_win64. That is where your PYTHONPATH variable should point to (if you use Python 3.5 or 3.6 then replace the 2.7 in the path by 3.5 or 3.6). Can you please double-check that your PYTHONPATH contains the absolute path of this folder? Also, can you print your PYTHONPATH from within your Python script to make sure it looks as expected:

    import os
    print(os.environ['PYTHONPATH'])

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Python DOCplex: Cannot find dll on Windows

    Posted Thu February 21, 2019 10:25 AM

    Originally posted by: WJvanHoeve


    The contents of my cplex/python folder are:

     Directory of C:\Program Files\IBM\ILOG\CPLEX_Studio128\python

    02/05/2019  04:27 PM    <DIR>          .
    02/05/2019  04:27 PM    <DIR>          ..
    02/05/2019  04:27 PM    <DIR>          dependencies
    02/19/2019  04:53 PM    <DIR>          docplex
    02/05/2019  04:27 PM    <DIR>          examples
    02/20/2019  10:24 PM            11,350 LICENSE.txt
    02/20/2019  10:24 PM             3,062 README.md
    02/20/2019  10:24 PM             4,040 setup.py
                   3 File(s)         18,452 bytes

    I ran 'setup.py' in this folder, and also manually added this path to my PYTHONPATH environment variable.

     

    This is the output of PYTHONPATH from within Python:

    C:\Program Files\IBM\ILOG\CPLEX_Studio128\python>python
    Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]
     on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> print(os.environ['PYTHONPATH'])
    C:\Program Files\IBM\ILOG\CPLEX_Studio128\python
    >>>


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Python DOCplex: Cannot find dll on Windows

    Posted Thu February 21, 2019 10:33 AM

    Do you have a folder C:\Program Files\IBM\ILOG\CPLEX_Studio128\cplex\python\3.6\x64_win64? Judging from your output I think that is the folder which contains the DLLs and to which PYTHONPATH should point. If you have that folder, can you try setting PYTHONPATH to include it?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Python DOCplex: Cannot find dll on Windows

    Posted Thu February 21, 2019 11:49 AM

    Originally posted by: WJvanHoeve


    Yes, that folder exists and I added it to the PYTHONPATH:

    >>> import os

    >>> print(os.environ['PYTHONPATH'])
    C:\Program Files\IBM\ILOG\CPLEX_Studio128\cplex\python\3.6\x64_win64
    >>>

    In Jupyter, now at least CPLEX is being recognized, but I received the message "Exception: CPLEX 12.8.0.0 is not compatible with this version of Python."

    In the command prompt, however, still get the error message "CPLEX DLL not found".  It also gives me the warning that "docplex is not officially supported on 32 bits, which made me realize that I was running a 32-bit version of Python :(.

     

    So, I installed the 64-bit version of Python 3.6.8, and re-executed all installation steps, including the setup.py -- this time from the proper path.

    Unfortunately, now I get a different error message: " ModuleNotFoundError: No module named 'docplex' ", see:

    C:\Program Files\IBM\ILOG\CPLEX_Studio128\python\examples\mp\modeling>python diet.py
    Traceback (most recent call last):
      File "diet.py", line 13, in <module>
        from docplex.mp.model import Model
    ModuleNotFoundError: No module named 'docplex'

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Python DOCplex: Cannot find dll on Windows

    Posted Thu February 21, 2019 11:55 AM

    Maybe it is a good idea to uninstall everything and restart from scratch.

    If the module "docplex" is not found then this means that it is not in the default places where Python looks for modules. You can try to add the docplex directory to PYTHONPATH as well. Or make sure that the python you invoke on the command line is indeed the one you intend to invoke. Maybe always use an absolute path to invoke python. Even when calling setup.py.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Python DOCplex: Cannot find dll on Windows

    Posted Thu February 21, 2019 01:16 PM

    Originally posted by: WJvanHoeve


    I uninstalled and restarted from scratch, but realized that my anaconda installation is based on Python 3.7 (which is not yet supported CPLEX), so I did not use conda.

    I am happy to report that the example diet.py now runs fine :)


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Python DOCplex: Cannot find dll on Windows

    Posted Mon April 15, 2019 04:31 AM

    Just a quick note: as of CPLEX version 12.9 Python 3.7 is now supported.


    #CPLEXOptimizers
    #DecisionOptimization