Registry / ai-ml / gurobipy

gurobipy

JSON →
library13.0.3pypypi✓ verified 21d ago

gurobipy is the official Python interface to the Gurobi Optimizer, a powerful mathematical optimization software library for solving mixed-integer linear, quadratic, and quadratically constrained programming problems. It provides convenient object-oriented modeling constructs and an API to all Gurobi features. The current version is 13.0.1, released on January 21, 2026, and it follows a regular release cadence with major versions typically released annually.

pip install gurobipy
INSTALL
IMPORT
SIG · GUROBIPY
G
gurobipy
ai-mlpythonv13.0.3
Install
2.2s avg
Import
60ms
Disk
70MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v13.0.3 · 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
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.060s · 73MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gurobipy
import gurobipy as gp
Standard alias for accessing Gurobi functions and classes.
GRB
from gurobipy import GRB
Imports Gurobi constants (e.g., GRB.OPTIMAL, GRB.MINIMIZE) directly without a prefix. Can also be accessed via `gp.GRB` if not imported directly.

This quickstart demonstrates a simple linear programming problem: maximizing `x + 2y` subject to `x + y <= 4` and `2x + y <= 5`. It shows how to create a model, add continuous variables, set an objective function, add constraints, and optimize the model. It also includes basic error handling for different optimization statuses.

import gurobipy as gp from gurobipy import GRB import os # NOTE: Gurobi requires a valid license. A trial license is included with pip install, # but for full functionality, a separate Gurobi Optimizer installation and license key # (e.g., academic or commercial) is typically required. # For demonstration, we'll assume a license is configured or a small problem is solved. # For academic license info: https://www.gurobi.com/downloads/end-user-license-agreement-academic/ # Create a new model m = gp.Model("quickstart_model") # Create variables x = m.addVar(vtype=GRB.CONTINUOUS, name="x", lb=0.0) y = m.addVar(vtype=GRB.CONTINUOUS, name="y", lb=0.0) # Set objective: Maximize x + 2y m.setObjective(x + 2 * y, GRB.MAXIMIZE) # Add constraint: x + y <= 4 m.addConstr(x + y <= 4, "c0") # Add constraint: 2x + y <= 5 m.addConstr(2 * x + y <= 5, "c1") # Optimize model m.optimize() if m.status == GRB.OPTIMAL: print(f"Optimal objective: {m.objVal}") print(f"x: {x.X}, y: {y.X}") elif m.status == GRB.UNBOUNDED: print("Model is unbounded") elif m.status == GRB.INF_OR_UNBOUNDED: print("Model is either infeasible or unbounded") elif m.status == GRB.INFEASIBLE: print("Model is infeasible") else: print(f"Optimization ended with status {m.status}")
Debug
Known issues
gotchaGurobi Optimizer requires a license for full functionality. While `pip install gurobipy` includes a limited trial license, solving larger or commercial problems necessitates obtaining and configuring a separate Gurobi license key. Academic licenses are available for students and faculty.
fix
Obtain a Gurobi license (academic, trial, or commercial) and ensure it is properly activated (e.g., by running `grbgetkey` or placing `gurobi.lic` in the correct location). Consult the official Gurobi installation and licensing guides for detailed instructions.
affects: All versions
breakingPreview features introduced in Gurobi 13.0, such as the new nonlinear barrier method, are explicitly noted as potentially undergoing significant changes in subsequent releases, 'including breaking changes in API, behavior or packaging'. This means code relying on these specific preview features may require adjustments in future minor or major Gurobi updates.
fix
Monitor Gurobi release notes for updates on preview features. Be prepared to refactor code that uses these features when upgrading Gurobi versions. For stable features, API compatibility is generally maintained within major versions.
affects: 13.0.x and later (for preview features)
gotchaFor optimal performance and to utilize the full Gurobi Optimizer capabilities, it is often recommended to download and install the full Gurobi Optimizer package from the Gurobi website, in addition to `pip installing` `gurobipy`. The `pip` package alone might use a more basic or limited installation.
fix
After `pip install gurobipy`, download and install the full Gurobi Optimizer from the official website. Ensure your Python environment is correctly configured to find the Gurobi installation, which is often handled automatically if the Optimizer is installed before `gurobipy` or by setting environment variables.
affects: All versions
breakingOlder versions of Python (e.g., Python 2.7, and specific older Python 3.x versions) are only compatible with corresponding older Gurobi releases. Attempting to use a recent `gurobipy` with an incompatible Python version will lead to errors. While PyPI lists `>=3.10` for `gurobipy` 13.0.1, Gurobi's general compatibility chart suggests broader (but version-dependent) support.
fix
Always check the Gurobi version compatibility guide to ensure your Python version is compatible with the specific Gurobi Optimizer release you are using. Upgrade Python or Gurobi as necessary to maintain compatibility.
affects: Potentially across all major versions if Python/Gurobi versions are mismatched.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'gurobipy'
The `gurobipy` package is not installed in the active Python environment or the wrong Python environment is being used.
fix
Install the Gurobi Python interface using `pip install gurobipy` or `conda install gurobi` (if using Anaconda) and ensure that the correct Python environment is activated.
gurobipy.GurobiError: Model too large for size-limited license
The optimization model exceeds the limits of the currently active Gurobi license, which is often a size-limited license included with `pip` or `conda` installations, or no valid full license is configured.
fix
Obtain a full Gurobi license (academic or commercial) and configure it correctly. This typically involves running `grbgetkey` with your license ID or placing the `gurobi.lic` file in a location where Gurobi can find it, such as your user home directory or the Gurobi installation directory.
AttributeError: 'gurobipy.Model' object has no attribute 'addVars'
The `gurobipy` version installed is older than the code expects, meaning it does not support newer API features like `addVars` (introduced in Gurobi 7.0) or `setObjectiveN` (introduced in Gurobi 7.5).
fix
Upgrade your `gurobipy` package to a newer version that supports the desired API functions. Use `pip install --upgrade gurobipy` or `conda update gurobi`.
ERROR: Could not find a version that satisfies the requirement gurobipy
The Python version being used is incompatible with the available `gurobipy` packages on PyPI or Conda, or there are other environment-specific issues preventing `pip` or `conda` from finding a suitable distribution.
fix
Ensure your Python version (e.g., 3.10, 3.11, 3.12, 3.13, 3.14 for Gurobi 13.0.1) is officially supported by the Gurobi version you are trying to install. Check the Gurobi documentation for supported platforms and Python versions.
AttributeError: 'gurobipy.Var' object has no attribute 'X'
This error occurs when attempting to access solution attributes (like `.X` for optimal value, `.LB` for lower bound) of a Gurobi variable before the optimization model has been successfully solved.
fix
Call `model.optimize()` before accessing variable attributes and verify that `model.Status` is `GRB.OPTIMAL` or another status indicating a solution is available.
Upgrade
Version history
13.0.3latest on PyPI · released Aug 25, 2026
Audit
Dependencies
Gurobi Optimizerrequiredgurobipy is a Python interface to the Gurobi Optimizer, which must be separately downloaded, installed, and licensed for full functionality.
numpyoptionalOptional dependency for numerical operations, especially with matrix-friendly API.
scipyoptionalOptional dependency for scientific computing, often used in conjunction with optimization problems.
gurobipy-pandasoptionalOptional wrapper library for easier integration with Pandas DataFrames and Series.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
gurobipy — pip install gurobipy · libregistry