{"id":8517,"library":"pyscipopt","title":"Python Interface and Modeling Environment for SCIP","description":"PySCIPOpt is a Python interface and modeling environment for the SCIP Optimization Suite, a powerful mixed-integer programming (MIP) and mixed-integer nonlinear programming (MINLP) solver. It allows users to formulate and solve optimization problems using Python syntax. The library is actively maintained with frequent releases, often coinciding with new major versions of the underlying SCIP solver.","status":"active","version":"6.1.0","language":"en","source_language":"en","source_url":"https://github.com/SCIP-Interfaces/PySCIPOpt","tags":["optimization","mathematical programming","MILP","MINLP","solver","SCIP"],"install":[{"cmd":"pip install pyscipopt","lang":"bash","label":"Standard Installation"},{"cmd":"conda install -c conda-forge pyscipopt","lang":"bash","label":"Conda Installation"}],"dependencies":[{"reason":"Required Python version.","package":"python","version":">=3.8"},{"reason":"PySCIPOpt is an interface to the SCIP solver. For versions 4.4.0 and newer, SCIP is bundled, but specific configurations (e.g., building from source, certain OS/Python combinations) might require a separate installation and linking.","package":"SCIP Optimization Suite","optional":true}],"imports":[{"symbol":"Model","correct":"from pyscipopt import Model"}],"quickstart":{"code":"from pyscipopt import Model, SCIP_STATUS\n\n# Create a SCIP model\nmodel = Model(\"Simple_LP\")\n\n# Add variables\nx = model.addVar(\"x\", vtype=\"CONTINUOUS\", lb=0.0)\ny = model.addVar(\"y\", vtype=\"CONTINUOUS\", lb=0.0)\n\n# Set the objective function: Maximize x + 2y\nmodel.setObjective(x + 2*y, \"maximize\")\n\n# Add constraints\nmodel.addCons(x + y <= 10, \"c1\")\nmodel.addCons(2*x + y <= 15, \"c2\")\n\n# Optimize the model\nmodel.optimize()\n\n# Check the solution status and print results\nif model.getStatus() == SCIP_STATUS.OPTIMAL:\n    print(f\"Optimal solution found.\")\n    print(f\"Objective value: {model.getObjVal()}\")\n    print(f\"x: {model.getVal(x)}\")\n    print(f\"y: {model.getVal(y)}\")\nelse:\n    print(f\"Problem could not be solved to optimality. Status: {model.getStatus()}\")\n\n# Clean up the model (important for repeated modifications/solves)\nmodel.freeProb()","lang":"python","description":"This quickstart demonstrates how to create a simple linear programming model, add variables, define an objective function, add constraints, optimize the model, and retrieve the solution. It also shows how to check the optimization status and explicitly free problem data."},"warnings":[{"fix":"Review the `CHANGELOG.md` for v6.0.0 and SCIP 10 release notes. Update code to use new features like IIS and exact solving, and adjust any deprecated or removed API calls.","message":"PySCIPOpt v6.0.0 introduced compatibility with SCIP 10, which includes significant changes to the underlying SCIP solver. This update removed some old methods (e.g., `chgAndConsCheckFlagWhenUpgr`, `chgAndConsRemovableFlagWhenUpgr`) and changed how nonlinear constraints are handled internally, which may affect existing code relying on older SCIP versions or specific API calls.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Always call `model.freeTransform()` before attempting to modify variables, constraints, or the objective of an already optimized model. For a full cleanup, use `model.freeProb()`.","message":"Modifying a model after it has been optimized without calling `freeTransform()` can lead to unexpected crashes or incorrect behavior. SCIP retains transformed problem data by default.","severity":"gotcha","affected_versions":"<6.1.0"},{"fix":"If precise dual values are critical, set appropriate SCIP parameters to disable presolving, propagation, and heuristics (e.g., `model.setParam('presolving/maxrounds', 0)`, `model.setParam('relaxing/maxrounds', 0)`, `model.setParam('heuristics/activated', 'off')`). Refer to SCIP documentation for specific parameters.","message":"Accessing dual values from the solution can be unreliable in default SCIP configurations. Accurate dual values are only guaranteed when presolving, propagation, and primal heuristics are disabled, and the problem has no bound constraints.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For ranged constraints, explicitly parenthesize the expression: `model.addCons(lhs <= (expression <= rhs), \"cons_name\")`. Alternatively, add single-sided constraints and modify bounds later using `chgRhs` or `chgLhs`.","message":"Python's operator overloading does not support chained comparisons for ranged constraints (e.g., `lhs <= expr <= rhs`). This syntax will not work as expected in PySCIPOpt.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For older versions, or if experiencing `scip/scip.h` not found errors, install the SCIP Optimization Suite separately and set the `SCIPOPTDIR` environment variable to its base directory before installing PySCIPOpt.","message":"Prior to v4.4.0, PySCIPOpt did not bundle the SCIP Optimization Suite. Installation via pip or source for older versions required manual installation of SCIP and setting the `SCIPOPTDIR` environment variable to point to its installation. Newer versions typically bundle SCIP, but this variable might still be needed for custom builds or specific environments.","severity":"gotcha","affected_versions":"<4.4.0 (and custom builds)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you have the SCIP Optimization Suite installed. If not bundled by PySCIPOpt (versions < 4.4.0) or for source builds, manually install SCIP and set the environment variable `SCIPOPTDIR` to the base directory of your SCIP installation (e.g., `export SCIPOPTDIR=/path/to/SCIPOptSuite`). Then retry `pip install pyscipopt`.","cause":"This typically occurs during installation when the underlying SCIP Optimization Suite development files are not found or linked correctly, especially in environments where SCIP is not bundled or `SCIPOPTDIR` is not set.","error":"Failed building wheel for pyscipopt / Cannot open include file: 'scip/scip.h': No such file or directory"},{"fix":"Run `pip install pyscipopt` (preferably within a virtual environment) or activate the correct Python environment where it was installed.","cause":"The `pyscipopt` package was either not installed, installed in a different Python environment, or the current environment is not activated.","error":"ModuleNotFoundError: No module named 'pyscipopt'"},{"fix":"Call `model.freeTransform()` before making any modifications to the model after it has been optimized. For a full reset, use `model.freeProb()`.","cause":"Changes were attempted on the model (e.g., adding variables/constraints) after an `optimize()` call without properly resetting the model's internal state.","error":"Segmentation fault / Crash when modifying model after optimization"},{"fix":"Use explicit parentheses for ranged constraints: `model.addCons(lhs <= (expression <= rhs))`.","cause":"Incorrect syntax used for defining ranged constraints, attempting `lhs <= expression <= rhs` directly.","error":"TypeError: unsupported operand type(s) for <: 'int' and 'Expr'"}]}