2
opt = SolverFactory('cplex', executable="/Applications/CPLEX_Studio_Community129/cplex/bin/x86-64_osx/cplex")

If using the executable option (as above), it works. If not, we get the following error:

ApplicationError: No executable found for solver 'cplex'
rkersh
  • 4,447
  • 2
  • 22
  • 31
chenglong0931
  • 33
  • 1
  • 3

2 Answers2

4

Try this

SolverFactory('cplex_direct')
2

If you don't want to specify the path with the executable option, you need to add the following directory to your PATH environment variable:

/Applications/CPLEX_Studio_Community129/cplex/bin/x86-64_osx

For example, you can do this from the command line, like so:

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

If that works, then you can make this permanent by adding it to your ~/.bash_profile using the technique described here

rkersh
  • 4,447
  • 2
  • 22
  • 31
  • Thank you so much for your help. "cplex" in the terminal window can work now (with Pyomo). However, when I typing"cplex" in the Anaconda without the executable option, it also prompt "No executable found for solver 'cplex' ". Can you give me some advices? – chenglong0931 Feb 05 '20 at 20:50
  • In Anaconda, what do you see if you add the following to your code: `import os; print("PATH=", os.getenv("PATH"))`? If you've set up your `~/.bash_profile` maybe you need to reboot? – rkersh Feb 05 '20 at 21:57
  • Thank you for your help. I fond that,if I tried typing `import os; print("PATH=", os.getenv("PATH"))` in the Anaconda,the path `/Applications/CPLEX_Studio_Community129/cplex/bin/x86-64_osx` is not list in the list. But, if I tried typing `python; import os; print("PATH=", os.getenv("PATH"))` in the terminal window, the path is list in the path list. Why the path of python in the Anaconda and terminal window are different? (the edition python is the same). Maybe that is the real reason for `No executable found for solver 'cplex'` in the Anaconda. – chenglong0931 Feb 06 '20 at 15:58
  • Are you using a [conda environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html)? What happens if you create a new conda environment? Does it then inherit the `PATH` from your system? – rkersh Feb 06 '20 at 16:56
  • No, I did not use a conda environment? I did not know why the original the conda environment is not inherit the `PATH` from the system? – chenglong0931 Feb 06 '20 at 20:26