Decision Optimization

Decision Optimization

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

 View Only
  • 1.  ModuleNotFoundError: No module named 'cplex.exceptions'

    Posted Tue February 02, 2021 02:57 PM
    Hello everyone,

    I am new to this board and really hope this is the right place for my question.

    I am trying to use optlang together with cplex (python 3.7 in Jupyter notebook, win10 64) and when running
    from optlang.cplex_interface import Model
    I get the error: ModuleNotFoundError: No module named 'cplex.exceptions' (the same thing also happens when I directly import cplex.exceptions).

    I downloaded CPLEX Optimization Studio 20.1 and installed cplex with setup.py install --home as described on this page:
    https://www.ibm.com/support/knowledgecenter/en/SSSA5P_12.8.0/ilog.odms.cplex.help/CPLEX/GettingStarted/topics/set_up/Python_setup.html
    I did struggle a bit with the installation but think that it ran correctly, as import cplex works just fine. The cplex package folder also contains a subfolder called exceptions.

    Does somebody know how I can fix this? Thanks very much!

    ------------------------------
    Oskar Wacker
    ------------------------------

    #DecisionOptimization


  • 2.  RE: ModuleNotFoundError: No module named 'cplex.exceptions'

    Posted Wed February 03, 2021 04:49 AM
    Edited by System Admin Fri January 20, 2023 04:09 PM
    Hello,

    So  you installed the wrappers using `python setup.py install etc.. ` in a termnail.
    Then you are running jupyter, and in a notebook, you cannot import cplex.exceptions.

    Are you sure that your jupyter is using the same python environment than the one you installed the wrappers in ?

    To be sure, you probably want to run the installation inside a jupyter noteook.
    Create a new notebook, with one cell (replace with your actual CPLEX Studio path), with that two lines:

    %cd "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.7\x64_win64"
    !pip install .

    Then restart your kernel.

    Best regards

    ------------------------------
    Viu Long Kong
    ------------------------------
    #DecisionOptimization


  • 3.  RE: ModuleNotFoundError: No module named 'cplex.exceptions'

    Posted Wed February 03, 2021 09:25 AM
    Thank you very much, that worked!

    Best regards

    ------------------------------
    Oskar Wacker
    ------------------------------



  • 4.  RE: ModuleNotFoundError: No module named 'cplex.exceptions'

    Posted Wed February 10, 2021 11:17 AM

    Hello,

    I am getting a similar error, but with Linux (Ubuntu 18.04.5 LTS x86_64), and directly from python.

    When trying to call cplex from a python package (micom), I get the error:

    CPLEX is available but could not load with error:

      Traceback (most recent call last):

        File "/home/username/.local/lib/python3.6/site-packages/optlang/__init__.py", line 43, in <module>

          from optlang import cplex_interface

        File "/home/vusername/.local/lib/python3.6/site-packages/optlang/cplex_interface.py", line 32, in <module>

          from cplex.exceptions import CplexSolverError

      ModuleNotFoundError: No module named 'cplex.exceptions'

    I noticed that python /opt/ibm/ILOG/CPLEX_Studio201/python/setup.py install
    failed to install enum, returning: AttributeError: module 'enum' has no attribute 'IntFlag'

    I found some stackoverflow topics about it, but none seemed to work here.

    Any clue on how can we solve this?

    Thanks!!!



    ------------------------------
    Vanessa Marcelino
    ------------------------------



  • 5.  RE: ModuleNotFoundError: No module named 'cplex.exceptions'

    Posted Thu February 11, 2021 05:07 AM
    Hi,

    COS 20.1 does not support python 3.6 - I guess this is why your initial install failed ?
    Please upgrade to python 3.7, make sure that your shell is setup to use your new python 3.7 environment, then do this:

    $ cd /opt/ibm/ILOG/CPLEX_Studio201/cplex/python/3.7/x86-64osx
    $ python setup.py install

    Best regards,


    ------------------------------
    Viu Long Kong
    ------------------------------



  • 6.  RE: ModuleNotFoundError: No module named 'cplex.exceptions'

    Posted Thu February 11, 2021 06:43 PM

    Hi,

    That explains it! 

    I installed it on a different server with Python 3.8 and that worked.

    Thanks a lot for the fast response!

    All the best,



    ------------------------------
    Vanessa Marcelino
    ------------------------------