{"id":4559,"library":"gurobipy","title":"Gurobi Python Interface (gurobipy)","description":"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.","status":"active","version":"13.0.1","language":"en","source_language":"en","source_url":"https://github.com/Gurobi/gurobipy","tags":["optimization","linear programming","mathematical programming","solver","mixed-integer programming","quadratic programming","commercial"],"install":[{"cmd":"pip install gurobipy","lang":"bash","label":"Install with pip (includes limited trial license)"},{"cmd":"conda install gurobi::gurobipy","lang":"bash","label":"Install with Conda (requires Gurobi channel setup)"}],"dependencies":[{"reason":"gurobipy is a Python interface to the Gurobi Optimizer, which must be separately downloaded, installed, and licensed for full functionality.","package":"Gurobi Optimizer","optional":false},{"reason":"Optional dependency for numerical operations, especially with matrix-friendly API.","package":"numpy","optional":true},{"reason":"Optional dependency for scientific computing, often used in conjunction with optimization problems.","package":"scipy","optional":true},{"reason":"Optional wrapper library for easier integration with Pandas DataFrames and Series.","package":"gurobipy-pandas","optional":true}],"imports":[{"note":"Standard alias for accessing Gurobi functions and classes.","symbol":"gurobipy","correct":"import gurobipy as gp"},{"note":"Imports Gurobi constants (e.g., GRB.OPTIMAL, GRB.MINIMIZE) directly without a prefix. Can also be accessed via `gp.GRB` if not imported directly.","symbol":"GRB","correct":"from gurobipy import GRB"}],"quickstart":{"code":"import gurobipy as gp\nfrom gurobipy import GRB\nimport os\n\n# NOTE: Gurobi requires a valid license. A trial license is included with pip install,\n# but for full functionality, a separate Gurobi Optimizer installation and license key\n# (e.g., academic or commercial) is typically required. \n# For demonstration, we'll assume a license is configured or a small problem is solved.\n# For academic license info: https://www.gurobi.com/downloads/end-user-license-agreement-academic/\n\n# Create a new model\nm = gp.Model(\"quickstart_model\")\n\n# Create variables\nx = m.addVar(vtype=GRB.CONTINUOUS, name=\"x\", lb=0.0)\ny = m.addVar(vtype=GRB.CONTINUOUS, name=\"y\", lb=0.0)\n\n# Set objective: Maximize x + 2y\nm.setObjective(x + 2 * y, GRB.MAXIMIZE)\n\n# Add constraint: x + y <= 4\nm.addConstr(x + y <= 4, \"c0\")\n\n# Add constraint: 2x + y <= 5\nm.addConstr(2 * x + y <= 5, \"c1\")\n\n# Optimize model\nm.optimize()\n\nif m.status == GRB.OPTIMAL:\n    print(f\"Optimal objective: {m.objVal}\")\n    print(f\"x: {x.X}, y: {y.X}\")\nelif m.status == GRB.UNBOUNDED:\n    print(\"Model is unbounded\")\nelif m.status == GRB.INF_OR_UNBOUNDED:\n    print(\"Model is either infeasible or unbounded\")\nelif m.status == GRB.INFEASIBLE:\n    print(\"Model is infeasible\")\nelse:\n    print(f\"Optimization ended with status {m.status}\")\n","lang":"python","description":"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."},"warnings":[{"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.","message":"Gurobi 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Preview 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.","severity":"breaking","affected_versions":"13.0.x and later (for preview features)"},{"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.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Older 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.","severity":"breaking","affected_versions":"Potentially across all major versions if Python/Gurobi versions are mismatched."}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}