Xarray error message using linopy

Hello there
I’ve some trouble by using linopy installed on my environment with the command: “conda install conda-forge::linopy” (successful).
When performing my first linear programming test code, it returns this error: “ImportError: cannot import name ‘Coordinates’ from ‘xarray’ (C:\Anaconda3\envs\Magpie_Linopy\lib\site-packages\xarray_init_.py)”
My configuration is Anaconda 2.0.3 and Python 3.8.18. Library linopy is 0.3.2, pandas is 2.0.3 and numpy 1.24.3.
Any help is wellcome.
Thk you

@pacoef,

It looks like the Coordinates class was introduced in xarray v2023.08.0 so you probably need a newer version of xarray.

It seems like linopy has only updated its required xarray version in the last few hours: require higher xarray version by lindnemi · Pull Request #218 · PyPSA/linopy · GitHub

It also seems like the conda-forge linopy feedstock didn’t update the constraint on the xarray dependency correctly for linopy 0.3.2. I have a pull request to fix this.

Until there’s a new release of linopy (hopefully soon), I would suggest you make sure you have xarray >=2023.9.0 and you should hopefully have the required version of the Coordinates class.

1 Like

Many thanks @xylar I couldn’t see xarray versions later than 2023.6.0 on my Anaconda environment 2.5.2. Thanks to you and this line code:
conda install -c conda-forge xarray dask netCDF4 bottleneck
(“Installation”),
I succeeded in updating xarray to the 2023.12.0 version.

And after installing a few solvers from linopy with this line in my env:
pip install linopy[solvers] (Getting Started — Linopy: Optimization with n-dimensional labeled variables), it works

Greetings

1 Like