{"id":23460,"library":"cplex","title":"CPLEX Python API (Community Edition)","description":"Python interface to the IBM ILOG CPLEX optimization engine (Community Edition). Provides access to CPLEX's LP, QP, QCP, and MILP solvers via the C Callable Library. Current version is 22.1.2.1, supporting Python >=3.9. Released approximately yearly.","status":"active","version":"22.1.2.1","language":"python","source_language":"en","source_url":"https://github.com/IBMDecisionOptimization/cplex-python","tags":["optimization","linear programming","mixed-integer programming","IBM","CPLEX"],"install":[{"cmd":"pip install cplex","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"High-level modeling wrapper (optional but recommended for most users; cplex alone is low-level)","package":"docplex","optional":true}],"imports":[{"note":"Using `import cplex` then `cplex.Cplex()` also works but is less common.","wrong":"import cplex (then using cplex.Cplex())","symbol":"Cplex","correct":"from cplex import Cplex"}],"quickstart":{"code":"import cplex\nfrom cplex.exceptions import CplexError\n\nprob = cplex.Cplex()\nprob.set_problem_name(\"example\")\nprob.objective.set_sense(prob.objective.sense.minimize)\n\n# Add variables\nnames = [\"x\", \"y\"]\nobj = [1.0, 2.0]\nlb = [0.0, 0.0]\nub = [cplex.infinity, cplex.infinity]\nprob.variables.add(obj=obj, lb=lb, ub=ub, names=names)\n\n# Add constraint: x + y == 1\nprob.linear_constraints.add(\n    lin_expr=[cplex.SparsePair(ind=[\"x\", \"y\"], val=[1.0, 1.0])],\n    senses=[\"E\"],\n    rhs=[1.0]\n)\n\nprob.solve()\nprint(\"Solution status:\", prob.solution.get_status())\nprint(\"x =\", prob.solution.get_values(\"x\"))\nprint(\"y =\", prob.solution.get_values(\"y\"))","lang":"python","description":"Solves a simple LP: minimize x + 2y subject to x + y = 1, x,y >= 0."},"warnings":[{"fix":"Upgrade Python to 3.9+ or downgrade CPLEX to 20.1 (which supports Python 3.6-3.8).","message":"CPLEX 22.1 dropped Python 3.6/3.7 support. Requires Python >=3.9.","severity":"breaking","affected_versions":">=22.1"},{"fix":"Use the full (non-community) licensed version for larger models.","message":"CPLEX Community Edition limits model size to 1000 variables and 1000 constraints. Attempting larger models raises CplexError.","severity":"gotcha","affected_versions":"all (Community Edition)"},{"fix":"Use multiprocessing (processes) instead of threading for parallel solves.","message":"Concurrent use of multiple Cplex instances is not thread-safe. Avoid creating Cplex objects in multiple threads without synchronization.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `problem.register_callback()` with the new callback classes (e.g., `cplex.callbacks.IncumbentCallback`).","message":"CPLEX 12.10 deprecated `cplex.callbacks` in favor of the CPLEX Callback API (C-type callbacks). Python interface updated accordingly.","severity":"deprecated","affected_versions":">=12.10"}],"env_vars":null,"search_vec":"'22.1.2.1':36 '3.9':39 'access':18 'api':3 'approxim':41 'c':30 'callabl':31 'communiti':4,15 'cplex':1,12,20,51 'current':33 'edit':5,16 'engin':14 'ibm':10,50 'ilog':11 'integ':48 'interfac':7 'librari':32 'linear':44 'lp':22 'milp':26 'mix':47 'mixed-integ':46 'optim':13,43 'program':45,49 'provid':17 'python':2,6,38 'qcp':24 'qp':23 'releas':40 'solver':27 'support':37 'version':34 'via':28 'year':42","created_at":"2026-05-01T08:07:53.488182+00:00","updated_at":"2026-05-01T08:07:53.488182+00:00","problems":[{"fix":"Reduce model size (Community cap) or use licensed CPLEX; if memory, simplify model or increase swap.","cause":"Model too large for Community Edition (1000x1000 limit) or system memory exhausted.","error":"CplexError: CPLEX Error  1001: Out of memory."},{"fix":"Run `pip install cplex` in the current environment (e.g., conda, virtualenv).","cause":"cplex package not installed or installed in wrong Python environment.","error":"ModuleNotFoundError: No module named 'cplex'"},{"fix":"Install CPLEX from IBM site (requires installer) or use pip version (includes binaries for common platforms). For pip version, ensure environment variable LD_LIBRARY_PATH includes site-packages/cplex.","cause":"CPLEX dynamic library not in library path (Linux) – typically due to missing CPLEX installation from IBM.","error":"ImportError: libcplex2212.so: cannot open shared object file: No such file or directory"},{"fix":"Check constraints and bounds; use `problem.feasopt()` to diagnose infeasibility.","cause":"Problem is infeasible or unbounded.","error":"CplexSolverError: CPLEX Error  1217: No solution exists."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"22.2.0.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://www.ibm.com/products/ilog-cplex-optimization-studio","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/cplex/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}