{"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,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","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,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}