Install & Compatibility
Where this runs
tested against v9.14.6206 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 255.7MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 9.3s · import 0.064s · 241MB
253MB installed
● package 253MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pywraplp
✓ from ortools.linear_solver import pywraplp
For Linear Programming (LP) and Mixed-Integer Programming (MIP).
cp_model
✓ from ortools.sat.python import cp_model
For Constraint Programming (CP-SAT solver).
routing_enums_pb2, pywrapcp
✓ from ortools.constraint_solver import routing_enums_pb2, pywrapcp
For Vehicle Routing Problems (using the legacy CP solver).
init
✓ from ortools.init.python import init
Required for initializing OR-Tools internals in some environments or older versions, though often implicitly handled now.
This quickstart demonstrates how to solve a simple linear programming problem using the GLOP solver via the `pywraplp` wrapper. It sets up variables, defines constraints, an objective function, and then solves and prints the results.
from ortools.linear_solver import pywraplp
def main():
# Create the linear solver with the GLOP backend.
solver = pywraplp.Solver.CreateSolver('GLOP')
if not solver:
return
# Create the variables x and y.
x = solver.NumVar(0, 1, 'x')
y = solver.NumVar(0, 2, 'y')
print('Number of variables =', solver.NumVariables())
# Define the constraints: x + y <= 2
solver.Add(x + y <= 2.0)
print('Number of constraints =', solver.NumConstraints())
# Define the objective function: Maximize 3 * x + y.
solver.Maximize(3 * x + y)
# Invoke the solver and display the results.
status = solver.Solve()
if status == pywraplp.Solver.OPTIMAL:
print('Solution:')
print('Objective value =', solver.Objective().Value())
print('x =', x.solution_value())
print('y =', y.solution_value())
else:
print('The problem does not have an optimal solution.')
print('\nAdvanced statistics:')
print('Problem solved in %f milliseconds' % solver.wall_time())
print('Problem solved in %d iterations' % solver.iterations())
if __name__ == '__main__':
main()
Debug
Known issues
breakingOR-Tools 9.x and later require Python 3.9 or higher. Support for Python 3.8 was dropped.fixUpgrade your Python environment to version 3.9 or newer. Ensure your `pip` is updated and use `pip install ortools`.
affects: 9.0.xxxx and later
deprecatedThe `MPSolver` for linear and mixed-integer programming is deprecated. Users should migrate to `ModelBuilder` or the newer `MathOpt` API for future compatibility and improved features. `MathOpt` is being actively developed and will eventually replace `ModelBuilder`.fixRewrite linear/MIP models using `ortools.linear_solver.model_builder` or `ortools.math_opt.python.mathopt` APIs. Refer to the official documentation for migration guides.
affects: 9.9.xxxx and later (MPSolver deprecated, ModelBuilder available), 10.0.x (MPSolver removed, MathOpt for Python/C++)
gotchaAfter OR-Tools 9.8, the CP-SAT Python API methods were refactored to use PEP8-compliant snake_case naming conventions (e.g., `solver.parameters.set_max_time_in_seconds`). While older CamelCase methods are currently still supported, it is best practice to update your code to use the snake_case equivalents to avoid potential future breakage or deprecation.fixUpdate method calls in your CP-SAT models to use snake_case (e.g., `solver.parameters.max_time_in_seconds = 10` instead of `solver.parameters.maxTimeInSeconds = 10`).
affects: 9.8.xxxx and later
gotchaUsing callbacks (e.g., `on_solution_callback` in CP-SAT) can significantly degrade search performance, especially if not implemented efficiently. Additionally, unhandled exceptions within these callbacks can lead to a Fatal Python error and program termination without a stack trace.fixMinimize complex operations within callbacks or avoid them if performance is critical. Always wrap callback logic in `try-except` blocks to gracefully handle and log exceptions.
affects: All versions with CP-SAT callbacks
gotchaIt's a common mistake to confuse Mixed-Integer Programming (MIP) solvers with Linear Programming (LP) solvers. Ensure you select the correct solver backend (e.g., `pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING` for MIP or `pywraplp.Solver.GLOP_LINEAR_PROGRAMMING` for LP) appropriate for your problem type, otherwise results may be incorrect (e.g., always returning 0 for integer variables if an LP solver is used for an MIP problem).fixExplicitly specify the correct solver type when creating a solver instance (e.g., `solver = pywraplp.Solver.CreateSolver('CBC_MIXED_INTEGER_PROGRAMMING')`). affects: All versions
breakingOR-Tools v10.0 is slated to migrate Python wrappers for routing and constraint_solver from SWIG to pybind11, which may introduce breaking changes in API structure or behavior. Additionally, Python 3.14 support has been identified as broken in some pre-release testing.fixMonitor OR-Tools release notes for v10.0. Be prepared for potential code adjustments, especially for routing and constraint programming APIs, and test thoroughly when upgrading. Consider holding off on Python 3.14 adoption until official support is confirmed.
affects: v10.0.x (expected late 2026/early 2027)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ortools'
The 'ortools' Python package is not installed in the current environment or the Python interpreter cannot locate it.
fixInstall the ortools library using pip: `python -m pip install ortools`
AttributeError: 'module' object has no attribute 'RoutingIndexManager'
The `RoutingIndexManager` class (or similar routing-related classes/functions like `pywrapcp`) is not directly accessible from the `ortools.constraint_solver` module, or the import path is incorrect, often due to changes in the library's internal structure across versions.
fixEnsure the correct specific imports are used, typically `from ortools.constraint_solver import pywrapcp` and `from ortools.constraint_solver import routing_enums_pb2` for routing problems, and then instantiate `RoutingIndexManager` using `pywrapcp.RoutingIndexManager()`.
TypeError: unsupported operand type(s) for +: 'int' and 'BoundedLinearExpression'
This error occurs in CP-SAT or linear solver models when attempting to perform arithmetic operations between Python native integers (or floats) and OR-Tools variable objects (like `IntVar`, `BoolVar`, or `BoundedLinearExpression`) without using the library's methods for building expressions, or by incorrectly using `sum()` with mixed types.
fixEnsure all terms in constraints and objectives are handled as OR-Tools expressions. For sums, use `model.Sum()` or ensure all elements within a Python `sum()` are compatible OR-Tools expressions. For example, use `model.Add(x + 2 * y <= 5)` where `x` and `y` are `IntVar` objects.
MODEL_INVALID (CpSolverStatus)
The CP-SAT model constructed contains an internal inconsistency or an invalid definition, such as variables with empty domains, contradictory constraints, or improperly defined expressions, which prevents the solver from processing it.
fixCall `solver.parameters.log_search_progress = True` to enable detailed logging, or use `model.Validate()` (for Python) after building the model to get specific validation errors and pinpoint the source of the invalidity. Examine variable domains and constraints for conflicts or incorrect bounds.
Upgrade
Version history
9.15.6755latest on PyPI · released Jan 14, 2026
Audit
Dependencies
pythonrequiredMinimum required Python version for ortools 9.x.