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
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)
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.
fixInstall 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().
fixAlways 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.
fixConvert 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