Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApplicationError: No executable found for solver 'cbc' #3477

Closed
david26694 opened this issue Feb 19, 2025 · 1 comment
Closed

ApplicationError: No executable found for solver 'cbc' #3477

david26694 opened this issue Feb 19, 2025 · 1 comment
Labels

Comments

@david26694
Copy link

Summary

Steps to reproduce the issue

$ which cbc
$ python example.py
# example.py
from pyomo.environ import *

# Create a model
model = ConcreteModel()

# Define variables (x, y >= 0)
model.x = Var(within=NonNegativeReals)
model.y = Var(within=NonNegativeReals)

# Define objective function (Maximize Z = 3x + 5y)
model.objective = Objective(expr=3 * model.x + 5 * model.y, sense=maximize)

# Define constraints
model.constraint1 = Constraint(expr=2 * model.x + 3 * model.y <= 12)
model.constraint2 = Constraint(expr=model.x + model.y <= 5)

# Solve the model using CBC
solver = SolverFactory('cbc')
result = solver.solve(model)

# Display results
model.display()

Error Message

$ ApplicationError: No executable found for solver 'cbc'

Information on your system

Pyomo version: Pyomo 6.8.2
Python version: 3.12.7
Operating system: macos sequoia, version 15.2
How Pyomo was installed (PyPI, conda, source): poetry
Solver (if applicable): cbc

Additional information

I also get False in here:

from pyomo.environ import SolverFactory

print("Available solvers:")
print(SolverFactory('cbc').available(exception_flag=False))  # Should return True
print(SolverFactory('ipopt').available(exception_flag=False))  # Should return True

but I run which cbc in terminal and it returns /usr/local/bin/cbc. I have also got this error during a .solve:

-> [2274](https://file+.vscode-resource.vscode-cdn.net/Users/davidmasip/Documents/Workspace/pricing-data/dynamic_pricing/notebooks/~/Documents/Workspace/pricing-data/dynamic_pricing/.venv/lib/python3.12/site-packages/pyomo/contrib/mindtpy/algorithm_base_class.py:2274)     raise ValueError(self.config.mip_solver + ' is not available.')
   [2275](https://file+.vscode-resource.vscode-cdn.net/Users/davidmasip/Documents/Workspace/pricing-data/dynamic_pricing/notebooks/~/Documents/Workspace/pricing-data/dynamic_pricing/.venv/lib/python3.12/site-packages/pyomo/contrib/mindtpy/algorithm_base_class.py:2275) if not self.mip_opt.license_is_valid():
   [2276](https://file+.vscode-resource.vscode-cdn.net/Users/davidmasip/Documents/Workspace/pricing-data/dynamic_pricing/notebooks/~/Documents/Workspace/pricing-data/dynamic_pricing/.venv/lib/python3.12/site-packages/pyomo/contrib/mindtpy/algorithm_base_class.py:2276)     raise ValueError(self.config.mip_solver + ' is not licensed.')

ValueError: cbc is not available.
@david26694 david26694 added the bug label Feb 19, 2025
@jsiirola
Copy link
Member

This looks like you are not running from a command line and instead are running from within vscode. Most likely, your vscode environment (particularly the PATH) doesn't match the environment you are using in a terminal. Fixing that should resolve your problem.

Alternatively, you can manually set the path to CBC with:

from pyomo.common import Executable
Executable('cbc').set_path('/usr/local/bin/cbc')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants