Registry / data / linopy

linopy

JSON →
library0.8.0pypypi✓ verified 84d ago

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.

pip install linopy
INSTALL
IMPORT
SIG · LINOPY
L
linopy
datapythonv0.8.0
Install
17.0s avg
Import
2372ms
Disk
552MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 16.7s
py 3.11
✓ —
✓ 16.25s
py 3.12
✓ —
✓ 16.35s
py 3.13
✓ —
✓ 17.3s
py 3.9
✕ build_error
✓ 18.55s
552MB installed
● package 552MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Model
from linopy import Model
from linopy.model import Model
Model is exported at package level; using submodule path may break if internal structure changes.
Variable
from linopy import Variable
from linopy.variables import Variable
Variable is part of the public API at top-level.
LinearExpression
from linopy import LinearExpression
from linopy.expressions import LinearExpression
LinearExpression is exported at package level.

Creates a simple linear optimization model with one variable, a constraint, and an objective. Solves with default solver (HiGHS if installed).

from linopy import Model import xarray as xr m = Model() # Create a variable with coords x = m.add_variables(name='x', lower=0, coords=[('i', [0,1,2])]) # Add constraint m.add_constraints(x.sum('i') <= 10, name='total') # Add objective m.add_objective(x.sum('i')) # Solve m.solve() # Retrieve solution print(x.solution)
Debug
Known issues
breakingIn 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.
fix
Set auto_mask=False when creating Model if you rely on unmasked behavior: Model(auto_mask=False)
affects: >=0.6.0
deprecatedThe 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.
fix
Use xr.DataArray with proper dims/coords instead of np.ndarray.
affects: >=0.5.0
gotchaScalar 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.
fix
Replace var[0] with var.values[0] or var.isel(i=0) where i is the dimension name.
affects: >=0.5.7
gotchaLinopy 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().
fix
Install a solver like HiGHS (pip install highspy) or Gurobi, and ensure it is on PATH or properly configured.
affects: >=0.1
Errors
Common errors & fixes
NoSolverAvailable: No solver found. Install a solver like highspy, gurobipy, or cplex, or set the `solver` argument.
No supported solver is installed or accessible in the environment.
fix
Install highspy: pip install highspy. Or install gurobipy if you have a license.
ValueError: cannot add variable without a name
You forgot to provide the name parameter in add_variables() or add_constraints().
fix
Always specify name='myvar' when adding variables or constraints.
TypeError: unhashable type: 'DataArray'
Using a DataArray as a dictionary key or index where hashable type is expected.
fix
Convert to tuple or string before use, or use .values.
Upgrade
Version history
0.8.0latest on PyPI · released Jun 10, 2026
Audit
Dependencies
xarrayrequiredCore dependency for labeled arrays
pandasrequiredUsed for data handling
numpyrequiredArray operations
scipyoptionalSome solver interfaces
polarsoptionalUsed for LP file writing in recent versions
Agent activity
8 hits · last 30 days
node
8
Resources
linopy — pip install linopy · libregistry