{"id":23117,"library":"linopy","title":"linopy","description":"Linear optimization with N-D labeled arrays in Python. Integrates with xarray and supports multiple solvers (HiGHS, Gurobi, CPLEX, etc.). Current version 0.6.7, released occasionally with bugfixes and performance improvements.","status":"active","version":"0.6.7","language":"python","source_language":"en","source_url":"https://github.com/PyPSA/linopy","tags":["optimization","linear programming","solver","xarray"],"install":[{"cmd":"pip install linopy","lang":"bash","label":"default"},{"cmd":"pip install linopy[gurobi]","lang":"bash","label":"with Gurobi"},{"cmd":"conda install -c conda-forge linopy","lang":"bash","label":"conda"}],"dependencies":[{"reason":"Core dependency for labeled arrays","package":"xarray","optional":false},{"reason":"Used for data handling","package":"pandas","optional":false},{"reason":"Array operations","package":"numpy","optional":false},{"reason":"Some solver interfaces","package":"scipy","optional":true},{"reason":"Used for LP file writing in recent versions","package":"polars","optional":true}],"imports":[{"note":"Model is exported at package level; using submodule path may break if internal structure changes.","wrong":"from linopy.model import Model","symbol":"Model","correct":"from linopy import Model"},{"note":"Variable is part of the public API at top-level.","wrong":"from linopy.variables import Variable","symbol":"Variable","correct":"from linopy import Variable"},{"note":"LinearExpression is exported at package level.","wrong":"from linopy.expressions import LinearExpression","symbol":"LinearExpression","correct":"from linopy import LinearExpression"}],"quickstart":{"code":"from linopy import Model\nimport xarray as xr\n\nm = Model()\n# Create a variable with coords\nx = m.add_variables(name='x', lower=0, coords=[('i', [0,1,2])])\n# Add constraint\nm.add_constraints(x.sum('i') <= 10, name='total')\n# Add objective\nm.add_objective(x.sum('i'))\n# Solve\nm.solve()\n# Retrieve solution\nprint(x.solution)\n","lang":"python","description":"Creates a simple linear optimization model with one variable, a constraint, and an objective. Solves with default solver (HiGHS if installed)."},"warnings":[{"fix":"Set auto_mask=False when creating Model if you rely on unmasked behavior: Model(auto_mask=False)","message":"In linopy v0.6.0, the auto_mask parameter was added to the Model class, changing its behavior for masked variables/constraints. Previously mask handling could be implicit; now the default is auto_mask=True which may mask out variables/constraints with zero coefficients. Set auto_mask=False to restore previous behavior.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Use xr.DataArray with proper dims/coords instead of np.ndarray.","message":"The use of xarray.DataArray for coefficients in add_variables and add_constraints is encouraged over numpy arrays. Passing raw numpy arrays may lead to unexpected broadcasting or lack of named dimensions.","severity":"deprecated","affected_versions":">=0.5.0"},{"fix":"Replace var[0] with var.values[0] or var.isel(i=0) where i is the dimension name.","message":"Scalar getitem on LinearExpression or Variable (e.g., expr[0]) raised FutureWarning in older versions and may be removed in future. Use .values or .isel() instead.","severity":"gotcha","affected_versions":">=0.5.7"},{"fix":"Install a solver like HiGHS (pip install highspy) or Gurobi, and ensure it is on PATH or properly configured.","message":"Linopy does not automatically install a solver. If no solver is found, solve() will raise an error. Common mistake: pip install linopy without solver, then call solve().","severity":"gotcha","affected_versions":">=0.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install highspy: pip install highspy. Or install gurobipy if you have a license.","cause":"No supported solver is installed or accessible in the environment.","error":"NoSolverAvailable: No solver found. Install a solver like highspy, gurobipy, or cplex, or set the `solver` argument."},{"fix":"Always specify name='myvar' when adding variables or constraints.","cause":"You forgot to provide the name parameter in add_variables() or add_constraints().","error":"ValueError: cannot add variable without a name"},{"fix":"Convert to tuple or string before use, or use .values.","cause":"Using a DataArray as a dictionary key or index where hashable type is expected.","error":"TypeError: unhashable type: 'DataArray'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}