{"id":9016,"library":"glpk","title":"PyGLPK","description":"PyGLPK (Python GLPK) is a Python module that provides a comprehensive interface to the GNU Linear Programming Kit (GLPK). It allows Python users to model and solve linear programming (LP), mixed integer programming (MIP), and other related optimization problems. The current version is 0.4.8. It has a moderate release cadence, largely tied to maintenance and updates related to the underlying GLPK C library.","status":"active","version":"0.4.8","language":"python","source_language":"en","source_url":"https://github.com/bradfordboyle/pyglpk","tags":["optimization","linear programming","MIP","GLPK","solver","OR"],"install":[{"cmd":"pip install glpk","lang":"bash","label":"Install PyGLPK"}],"dependencies":[{"reason":"PyGLPK is a wrapper around the GLPK C library and requires it to be pre-installed on the system. It is not automatically installed by pip.","package":"GNU Linear Programming Kit (GLPK) C library","optional":false}],"imports":[{"symbol":"GLPK","correct":"from glpk import GLPK"},{"symbol":"LP","correct":"from glpk import LP"},{"symbol":"Var","correct":"from glpk import Var"},{"symbol":"Term","correct":"from glpk import Term"},{"note":"Represents infinity for variable bounds.","symbol":"N","correct":"from glpk import N"},{"note":"Represents a continuous variable kind.","symbol":"C","correct":"from glpk import C"},{"note":"Represents row/constraint.","symbol":"R","correct":"from glpk import R"}],"quickstart":{"code":"from glpk import LP, Var, N, C, GLPK\n\n# Create a new problem\nlp = LP()\n\n# Define variables\nx1 = lp.add_var(name='x1', lb=0.0, ub=N, kind=C) # lb=0, ub=infinity, continuous\nx2 = lp.add_var(name='x2', lb=0.0, ub=N, kind=C)\n\n# Set objective function (maximize 10*x1 + 6*x2)\nlp.obj.dir = LP.MAX\nlp.obj += 10 * x1 + 6 * x2\n\n# Add constraints\n# Constraint 1: x1 + x2 <= 100\nc1 = lp.add_row(name='c1')\nc1.add_term(x1, 1.0)\nc1.add_term(x2, 1.0)\nc1.upper_bound = 100.0\n\n# Constraint 2: 7*x1 + 3*x2 <= 350\nc2 = lp.add_row(name='c2')\nc2.add_term(x1, 7.0)\nc2.add_term(x2, 3.0)\nc2.upper_bound = 350.0\n\n# Constraint 3: 3*x1 + 5*x2 <= 150\nc3 = lp.add_row(name='c3')\nc3.add_term(x1, 3.0)\nc3.add_term(x2, 5.0)\nc3.upper_bound = 150.0\n\n# Solve the problem\nlp.simplex()\n\n# Print results\nif lp.status == GLPK.LP_OPT:\n    print(f\"Status: Optimal\")\n    print(f\"Objective value: {lp.obj.value:.2f}\")\n    print(f\"x1 = {x1.value:.2f}\")\n    print(f\"x2 = {x2.value:.2f}\")\nelif lp.status == GLPK.LP_FEAS:\n    print(f\"Status: Feasible, but not necessarily optimal\")\n    print(f\"Objective value: {lp.obj.value:.2f}\")\n    print(f\"x1 = {x1.value:.2f}\")\n    print(f\"x2 = {x2.value:.2f}\")\nelse:\n    print(f\"Status: Solver terminated with status code: {lp.status}\")\n\n# Clean up\nlp.delete()","lang":"python","description":"This quickstart defines and solves a simple linear programming problem with two continuous variables and three constraints. It demonstrates variable definition, objective function setup, constraint creation, solving the problem, and interpreting the results."},"warnings":[{"fix":"Install the GLPK C library for your operating system. For Debian/Ubuntu: `sudo apt-get install libglpk-dev`. For macOS (Homebrew): `brew install glpk`. For Windows, you typically need to build from source or use a pre-compiled binary and ensure it's in your system's PATH.","message":"PyGLPK requires the GLPK C library to be installed on your system BEFORE installing the Python package. The Python package is a wrapper; it does not install the underlying C library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always explicitly set `kind` (C, I, B for continuous, integer, binary respectively) and `lb` (lower bound) / `ub` (upper bound) for variables. Use `N` from `glpk` for infinity.","message":"Be mindful of variable types (continuous, integer, binary) and bounds. Incorrectly defined variables can lead to infeasible or unbounded solutions, or incorrect solver behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `if lp.status == GLPK.LP_OPT:` instead of `if lp.status == 5:` (or other magic numbers). Refer to GLPK documentation for all status constants.","message":"The GLPK solver's status codes (e.g., `lp.status`) are integers. For clear and robust interpretation, always compare them against constants from the `glpk.GLPK` module (e.g., `GLPK.LP_OPT`, `GLPK.LP_FEAS`).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.4.8':45 'allow':22 'c':63 'cadenc':51 'comprehens':12 'current':42 'glpk':4,20,62,69 'gnu':16 'integ':33 'interfac':13 'kit':19 'larg':52 'librari':64 'linear':17,29,66 'lp':31 'mainten':55 'mip':35,68 'mix':32 'model':26 'moder':49 'modul':8 'optim':39,65 'problem':40 'program':18,30,34,67 'provid':10 'pyglpk':1,2 'python':3,7,23 'relat':38,58 'releas':50 'solv':28 'solver':70 'tie':53 'under':61 'updat':57 'user':24 'version':43","created_at":"2026-04-16T18:48:02.200988+00:00","updated_at":"2026-04-16T18:48:02.200988+00:00","problems":{"verify_error":"× Failed to build `glpk==0.4.8`\n  ├─▶ The build backend returned an error\n  ╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit\n      status: 1)\n\n      [stdout]\n      running bdist_wheel\n      running build\n      running build_ext\n      building 'glpk' extension\n      creating bu"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.4.8","cli_name":"","cli_version":null,"type":"library","homepage":"https://www.gnu.org/software/glpk/","github":"https://github.com/bradfordboyle/pyglpk","docs":null,"changelog":null,"pypi":"https://pypi.org/project/glpk/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"install_fail","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}