{"id":3511,"library":"highspy","title":"High-performance Open-source Mixed-Integer Linear Optimization Solver (HiGHS) Python Interface","description":"highspy is a thin set of pybind11 wrappers to HiGHS, a high-performance serial and parallel solver for large-scale sparse linear optimization, convex quadratic programming, and mixed-integer programming problems. It is currently at version 1.14.0 and maintains an active development and release cadence.","status":"active","version":"1.14.0","language":"python","source_language":"en","source_url":"https://github.com/ERGO-Code/HiGHS","tags":["optimization","linear programming","mixed integer programming","LP","MIP","solver","quadratic programming"],"install":[{"cmd":"pip install highspy","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for numerical array operations and data handling.","package":"numpy","optional":false}],"imports":[{"symbol":"Highs","correct":"import highspy\nh = highspy.Highs()"},{"symbol":"HighsLp","correct":"from highspy import HighsLp\nlp = HighsLp()"},{"note":"Enums are accessed via the enum class (e.g., ObjSense) within the highspy module, not directly as module-level constants.","wrong":"highspy.kMaximize","symbol":"ObjSense","correct":"from highspy import ObjSense\nlp.sense_ = ObjSense.kMaximize"}],"quickstart":{"code":"import highspy\nimport numpy as np\n\nh = highspy.Highs()\n\n# Define an LP problem (maximize 8x0 + 10x1 subject to constraints)\nlp = highspy.HighsLp()\nlp.num_col_ = 2\nlp.num_row_ = 2\nlp.sense_ = highspy.ObjSense.kMaximize\nlp.col_cost_ = np.array([8, 10], dtype=np.double)\nlp.col_lower_ = np.array([0, 0], dtype=np.double)\nlp.col_upper_ = np.array([highspy.kHighsInf, highspy.kHighsInf], dtype=np.double)\nlp.row_lower_ = np.array([-highspy.kHighsInf, -highspy.kHighsInf], dtype=np.double)\nlp.row_upper_ = np.array([120, 210], dtype=np.double)\n\n# Constraint matrix A (row-wise in this example for illustration)\n# 0.3*x0 + 0.5*x1 <= 120\n# 0.7*x0 + 0.5*x1 <= 210\nlp.a_matrix_.start_ = np.array([0, 2, 4]) # Column starts (for column-wise storage, but example uses row-wise interpretation)\nlp.a_matrix_.index_ = np.array([0, 1, 0, 1]) # Row indices for each element\nlp.a_matrix_.value_ = np.array([0.3, 0.7, 0.5, 0.5], dtype=np.double)\n\nh.passModel(lp)\n\n# Solve the model\nh.run()\n\n# Extract and print solution\nsolution = h.getSolution()\ninfo = h.getInfo()\nmodel_status = h.getModelStatus()\n\nprint(f\"Model status: {h.modelStatusToString(model_status)}\")\nif model_status == highspy.HighsModelStatus.kOptimal:\n    col_value = list(solution.col_value)\n    print(f\"Optimal objective: {info.obj_val}\")\n    print(f\"x0 = {col_value[0]}, x1 = {col_value[1]}\")\nelse:\n    print(\"No optimal solution found.\")","lang":"python","description":"This quickstart demonstrates how to define and solve a simple Linear Programming (LP) problem using `highspy`. It constructs an `HighsLp` object, populates it with objective coefficients, variable bounds, and constraint matrix, then passes it to the HiGHS solver instance to find an optimal solution."},"warnings":[{"fix":"Convert solution arrays to lists: `col_value = list(solution.col_value)` before accessing elements.","message":"Direct iteration or element-wise access of returned array-like solution values (e.g., `solution.col_value`) can be very slow. It is highly recommended to convert these to Python lists first for efficient access.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If an expression needs to be reused, ensure you are working with a copy or construct expressions explicitly for each use. More robust expression building might be available in newer versions (e.g., `ExprBuilder` mentioned in related discussions).","message":"When constructing linear expressions, the `highs_linear_expression.__add__` method modifies the expression in-place. Reusing an expression object after it has been modified can lead to unexpected and hard-to-debug results.","severity":"gotcha","affected_versions":"Versions prior to 1.14.0, and potentially current if not careful."},{"fix":"Use `h.setOptionValue('log_file', 'your_log_file.txt')` on your `highspy.Highs` instance to specify a log file.","message":"By default, HiGHS C++ logging is duplicated to `Highs.log`. In `highspy`, to redirect logging output to a specific file, you must explicitly set the 'log_file' option.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the documentation of the integrating modeling library. It may require setting an environment variable like `PMIP_HIGHS_LIBRARY` to explicitly point to the HiGHS shared library.","message":"Users integrating `highspy` with other modeling libraries like `python-mip` might encounter `FileNotFoundError: HiGHS not found` even after `highspy` is installed. This suggests a solver discovery issue in the integrating library.","severity":"gotcha","affected_versions":"Observed with `python-mip` v1.9.0 and earlier."},{"fix":"For high-level modeling, prefer `addVariable` and `addConstr` if available in your `highspy` version. For direct interaction with the solver's underlying data structures, use `addCol` and `addRow`.","message":"The `addVar` method within the direct `highspy` modeling interface was noted for clashes and potential confusion with internal methods. A new method, `addVariable`, is being introduced for clearer high-level modeling.","severity":"deprecated","affected_versions":"Versions 1.5.3, 1.7.1.dev1, and potentially others. Users attempting to use `addVar` for high-level modeling might experience issues."}],"env_vars":null,"search_vec":"'1.14.0':55 'activ':59 'cadenc':63 'convex':41 'current':52 'develop':60 'high':2,13,25,28 'high-perform':1,27 'highspi':16 'integ':9,47,68 'interfac':15 'larg':36 'large-scal':35 'linear':10,39,65 'lp':70 'maintain':57 'mip':71 'mix':8,46,67 'mixed-integ':7,45 'open':5 'open-sourc':4 'optim':11,40,64 'parallel':32 'perform':3,29 'problem':49 'program':43,48,66,69,74 'pybind11':22 'python':14 'quadrat':42,73 'releas':62 'scale':37 'serial':30 'set':20 'solver':12,33,72 'sourc':6 'spars':38 'thin':19 'version':54 'wrapper':23","created_at":"2026-04-11T17:32:44.958250+00:00","updated_at":"2026-04-16T15:34:11.859282+00:00","problems":[{"fix":"For Windows, ensure the Microsoft Visual C++ Redistributable for Visual Studio 2015-2022 is installed. If using a `conda` environment, explicitly activate it before running your Python script. Reinstalling `highspy` in a clean virtual environment can also resolve the issue.","cause":"This error typically occurs on Windows when the `highspy` Python package cannot load its underlying C++ shared library (DLL), often due to missing Microsoft Visual C++ Redistributable packages or environmental issues within a Python environment like Anaconda.","error":"ImportError: DLL load failed while importing highs_bindings: The specified procedure could not be found."},{"fix":"It is recommended to install `highspy` using `pip` (`pip install highspy`) and avoid `conda` for `highspy` specifically, as `pip` installations are officially supported and tend to resolve these linking issues on macOS. Ensure `pip` and `setuptools` are up to date before installing.","cause":"This `ImportError` on macOS indicates a problem with the dynamic linking of the `highspy` shared library, where a required symbol (like a specific C++ function) is not found. This can happen if `highspy` was installed via `conda` rather than `pip`, or if there are version mismatches.","error":"ImportError: dlopen(.../highs_bindings.cpython-xxx-darwin.so, 0x0002): symbol not found in flat namespace '__ZN5Highs10clearModelEv'."},{"fix":"Construct the optimization model using `highspy`'s explicit API by populating a `highspy.HighsModel` object. This involves setting attributes such as `col_lower`, `col_upper`, `row_lower`, `row_upper`, `a_matrix_start`, `a_matrix_index`, `a_matrix_value`, and `obj_coeffs` directly, rather than using convenience methods like `addConstr`. Refer to the official `highspy` examples for correct model formulation.","cause":"This error arises when a user attempts to use a modeling API style (like `addConstr` for adding constraints) that is common in higher-level optimization modeling libraries (e.g., Pyomo, Gurobi) but is not directly available in `highspy`'s lower-level Python bindings to HiGHS. The `highspy` library exposes a direct interface to the HiGHS solver's C++ API.","error":"AttributeError: 'Highs' object has no attribute 'addConstr'"},{"fix":"First, ensure `highspy` is installed (`pip install highspy`). If the error persists, set the `PMIP_HIGHS_LIBRARY` environment variable to the full path of the `highs_bindings` shared library file within your `highspy` installation (e.g., `C:\\path\\to\\venv\\Lib\\site-packages\\highspy\\_core.cpXX-win_amd64.pyd` on Windows or `.so`/`.dylib` on Linux/macOS).","cause":"This specific error occurs when using `python-mip` with `highspy` and `python-mip` cannot locate the HiGHS solver's shared library or executable, even if `highspy` is installed. This often indicates that `python-mip` needs to be explicitly told where the HiGHS library resides.","error":"FileNotFoundError: HiGHS not found. Please install the `highspy` package, or set the `PMIP_HIGHS_LIBRARY` environment variable."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.15.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://highs.dev","github":"https://github.com/ERGO-Code/HiGHS","docs":null,"changelog":null,"pypi":"https://pypi.org/project/highspy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-29","next_check":"2026-07-28","install_tag":null}}