Summary
When using the CBC solver on Fedora, you get the following error even with the coin-or-Cbc package installed. The cause is simple: most distros name the cbc binary cbc, but Fedora names it Cbc. Pyomo always uses cbc
Steps to reproduce the issue
#!/usr/bin/env python3
"""
Minimal reproducible example for Pyomo CBC solver issue on Fedora.
"""
import shutil
import sys
print("Checking for CBC executables:")
print(f" which cbc: {shutil.which('cbc') or 'NOT FOUND'}")
print(f" which Cbc: {shutil.which('Cbc') or 'NOT FOUND'}")
from pyomo.environ import SolverFactory, ConcreteModel, Var, Objective
# Try to create CBC solver
solver = SolverFactory('cbc')
if not solver.available():
print("FAILURE: Pyomo cannot find CBC solver")
print(" Even though /usr/bin/Cbc exists!")
sys.exit(1)
# Try to solve a simple problem
model = ConcreteModel()
model.x = Var(bounds=(0, 10))
model.obj = Objective(expr=model.x)
try:
results = solver.solve(model)
print(f"SUCCESS: x = {model.x.value}")
except Exception as e:
print(f"FAILURE: {e}")
sys.exit(1)
Gives:
Checking for CBC executables:
which cbc: NOT FOUND
which Cbc: /usr/bin/Cbc
FAILURE: Pyomo cannot find CBC solver
Even though /usr/bin/Cbc exists!
Error Message
self = <pyomo.solvers.plugins.solvers.CBCplugin.CBCSHELL object at 0x7f0740772390>
exception_flag = True
def available(self, exception_flag=False):
"""True if the solver is available"""
if self._assert_available:
return True
if not OptSolver.available(self, exception_flag):
return False
try:
# HACK: Suppress logged warnings about the executable not
# being found
cm = nullcontext() if exception_flag else LoggingIntercept()
with cm:
ans = self.executable()
except NotImplementedError:
ans = None
if ans is None:
if exception_flag:
msg = "No executable found for solver '%s'"
> raise ApplicationError(msg % self.name)
E pyomo.common.errors.ApplicationError: No executable found for solver 'cbc'
.venv/lib/python3.12/site-packages/pyomo/opt/solver/shellcmd.py:140: ApplicationError
Information on your system
Pyomo version: 6.8.2
Python version: 3.12
Operating system: Fedora 43
How Pyomo was installed (PyPI, conda, source): UV (PyPi)
Solver (if applicable):
Additional information
Summary
When using the CBC solver on Fedora, you get the following error even with the
coin-or-Cbcpackage installed. The cause is simple: most distros name the cbc binarycbc, but Fedora names itCbc. Pyomo always usescbcSteps to reproduce the issue
Gives:
Error Message
Information on your system
Pyomo version: 6.8.2
Python version: 3.12
Operating system: Fedora 43
How Pyomo was installed (PyPI, conda, source): UV (PyPi)
Solver (if applicable):
Additional information