pulp.solvers.PulpSolverError: PuLP: cannot execute cplex

Viewed 1424

I am trying to solve an MIP using PuLP on a Mac. I have already added the directory '/Applications/CPLEX_Studio1210/cplex/python/3.7/x86-64_osx', to my PYTHONPATH. But whenever I try

prob.solve(CPLEX_CMD()),

I receive the following error message:

File "/Users/xxxx/opt/anaconda3/envs/pulposm/lib/python3.7/site-packages/pulp/solvers.py", line 468, in actualSolve
    raise PulpSolverError("PuLP: cannot execute "+self.path)
pulp.solvers.PulpSolverError: PuLP: cannot execute cplex.
2 Answers

This is closely related to this stackoverflow question, but slightly different because you are on a Mac rather than Windows. The gist of the answer is the same, though. As mentioned in the comments, you need to set the PATH environment variable (not PYTHONPATH) so that the cplex binary can be executed by PuLP.

In your case, this should look something like this:

$ export PATH=$PATH:/Applications/CPLEX_Studio1210/cplex/bin/x86-64_osx

See also, this stackoverflow question about setting environment variables on OS X and making them persist.

Alternately, you can set the path argument to the location of the cplex executable in the CPLEX_CMD constructor (see the source code).

can you try

import pulp
import cplex
bus_problem = pulp.LpProblem("bus", pulp.LpMinimize)
nbBus40 = pulp.LpVariable('nbBus40', lowBound=0, cat='Integer')
nbBus30 = pulp.LpVariable('nbBus30', lowBound=0, cat='Integer')

# Objective function
bus_problem += 500 * nbBus40 + 400 * nbBus30, "cost"

# Constraints
bus_problem += 40 * nbBus40 + 30 * nbBus30 >= 300
bus_problem.solve(pulp.CPLEX())

print(pulp.LpStatus[bus_problem.status])
for variable in bus_problem.variables():
    print ("{} = {}".format(variable.name, variable.varValue))

from https://medium.com/@alexfleischer_84755/optimization-simply-do-more-with-less-zoo-buses-and-kids-part2-python-java-c-cc04558e49b5

Related