0

I have a mathematical model with the .mod ("trial.mod") extension and data file with the extension of .dat on cplex; I want to import this model and the initial solution of it to the python to develop a sort of improvement heuristic which is based on the initial solution.

To do that, I applied

main { 
thisOplModel.generate(); 
cplex.exportModel("trial.lp")
}

at the end of the .mod file. My Python code is:

import cplex

import sys

def  sample(filename):

    c = cplex.Cplex("trial.lp")
    try:
        c.solve()
    except CplexSolverError:
        print ("Exception raised during solve")
    return
    status = c.solution.get_status()
    print ("Solution status = " , status, ":",)
    print (c.solution.status[status])
    print ("Objective value = " , c.solution.get_objective_value())

When I run my Python code I am getting "No module called 'cplex' error.

What is my mistake, how can I correct my Python code to reach the aim?

I use Cplex 12.6

halfer
  • 19,824
  • 17
  • 99
  • 186
Angelıque
  • 15
  • 7
  • 1
    https://stackoverflow.com/questions/45234827/importerror-no-module-named-cplex-python-on-linux – Harry Sep 30 '17 at 19:52
  • Same question at https://www.ibm.com/developerworks/community/forums/html/topic?id=c49b199a-25ee-4586-8b69-5792482bea0f&ps=25 – Alex Fleischer Oct 02 '17 at 05:48
  • A now-deleted answer gave [this link](https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cplex.help/CPLEX/GettingStarted/topics/set_up/Python_setup.html). – halfer Apr 08 '21 at 09:20

0 Answers0