Decision Optimization

 View Only
  • 1.  Error using CPLEX and Python

    Posted Mon March 29, 2021 08:33 PM
    I tried to run CPLEX with IDLE (Python 3.9 64-bit) but I received the following message:

    Traceback (most recent call last):
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 290, in get_cplex_module
    import cplex #@UnresolvedImport
    ModuleNotFoundError: No module named 'cplex'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\Users\Acer\OneDrive\#####PRODEGI\4º Sem\Optimization\FinalAssignement\", line 67, in <module>
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 417, in __init__
    self._environment = self._make_environment()
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 181, in _make_environment
    env = Environment.get_default_env()
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 427, in get_default_env
    Environment._default_env = Environment.make_new_configured_env()
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 422, in make_new_configured_env
    return Environment(start_auto_configure=True)
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 84, in __init__
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 220, in auto_configure
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 328, in check_cplex
    cplex = self.get_cplex_module(logger=logger)
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 314, in get_cplex_module
    cplex = load_cplex_from_cos_root(loc) if loc else None
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 286, in load_cplex_from_cos_root
    return load_cplex(full_path, version=version)
    File "C:\Users\Acer\AppData\Local\Programs\Python\Python39\lib\site-packages\docplex\mp\", line 261, in load_cplex
    raise FileNotFoundError("Could not load module from %s" % module_location)
    FileNotFoundError: Could not load module from C:\Program Files\IBM\ILOG\CPLEX_Studio_Community201\cplex\python\3.9\x64_win64\cplex\

    Can you help me?

    Carlos Cesar Martins Ferreira


  • 2.  RE: Error using CPLEX and Python

    Posted Wed March 31, 2021 04:11 AM
    Hi Carlos,

    CPLEX 20.1 does not support python 3.9 - so when docplex wants to find the CPLEX python api wrappers, it fails.
    The error message is ugly (FileNotFoundError), I'm filing an issue so that we have a more user friendly message.

    Viu Long Kong

  • 3.  RE: Error using CPLEX and Python

    Posted Tue December 06, 2022 10:03 AM
    When you open a file with the name "filename.ext"; you are telling the open() function that your file is in the current working directory . This is called a relative path.

    file = open('filename.ext') //relative path

    In the above code, you are not giving the full path to a file to the open() function, just its name - a relative path. The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path.

    file = open(r'C:\path\to\your\filename.ext') //absolute path

    In the above code, all of the information needed to locate the file is contained in the path string - absolute path.

    If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the python file path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. In order to make this work, the directory containing the python executable must be in the PATH, a so-called environment variable that contains directories that are automatically used for searching executables when you enter a command. In any case, if your Python script file and your data input file are not in the same directory, you always have to specify either a relative path between them or you have to use an absolute path for one of them.

    john malib