saeyslab / napari-sparrow

https://sparrow-pipeline.readthedocs.io/en/latest/
Other
23 stars 0 forks source link

Error in import sparrow as sp #208

Open galib36 opened 1 day ago

galib36 commented 1 day ago

Hello, Thank you for creating this great workflow. I am trying to analyze my MERSCOPE data using this tool. After successfully installing the program when I run

import sparrow as sp

it gives the following error

cannot import name 'HybridMappingProxy' from 'xarray.core.utils'

The detail of the error are given below, can you please suggest how I can fix this issue.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[4], line 1
----> 1 from sparrow.datasets.registry import get_registry

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/__init__.py:9
      5 import os
      7 os.environ["USE_PYGEOS"] = "0"
----> 9 from . import (  # noqa: E402
     10     datasets,
     11     io,
     12     utils,
     13 )
     14 from . import image as im  # noqa: E402
     15 from . import plot as pl  # noqa: E402

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/datasets/__init__.py:1
----> 1 from .cluster_blobs import cluster_blobs, multisample_blobs
      2 from .pixie_example import pixie_example
      3 from .proteomics import macsima_example, mibi_example, vectra_example

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/datasets/cluster_blobs.py:16
     13 from spatialdata.models import Image2DModel, Labels2DModel, PointsModel, TableModel
     14 from spatialdata.transformations import Identity
---> 16 from sparrow.table import add_regionprop_features
     17 from sparrow.utils._keys import _CELL_INDEX, _INSTANCE_KEY, _REGION_KEY
     18 from sparrow.utils.pylogger import get_pylogger

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/table/__init__.py:1
----> 1 from ._allocation import allocate, bin_counts
      2 from ._allocation_intensity import allocate_intensity
      3 from ._annotation import cluster_cleanliness, score_genes, score_genes_iter

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/table/_allocation.py:20
     17 from spatialdata.transformations import Identity
     18 from xarray import DataArray
---> 20 from sparrow.image._image import _get_spatial_element, _get_translation
     21 from sparrow.shape._shape import filter_shapes_layer
     22 from sparrow.table._table import add_table_layer

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/image/__init__.py:1
----> 1 from sparrow.utils.pylogger import get_pylogger
      3 from ._apply import map_channels_zstacks
      4 from ._combine import combine

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/utils/__init__.py:1
----> 1 from sparrow.utils._query import bounding_box_query
      2 from sparrow.utils.pylogger import get_pylogger
      3 from sparrow.utils.utils import _export_config, _get_polygons_in_napari_format, _get_raster_multiscale

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/utils/_query.py:10
      7 from spatialdata import bounding_box_query as bounding_box_query_spatialdata
      8 from spatialdata.transformations import get_transformation
---> 10 from sparrow.image._image import _get_spatial_element, add_labels_layer
     11 from sparrow.table._table import add_table_layer
     12 from sparrow.utils._keys import _INSTANCE_KEY, _REGION_KEY

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/sparrow/image/_image.py:9
      7 import xarray as xr
      8 from dask.array import Array
----> 9 from datatree import DataTree
     10 from spatialdata import SpatialData
     11 from spatialdata.models._utils import MappingToCoordinateSystem_t

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/datatree/__init__.py:2
      1 # import public API
----> 2 from .datatree import DataTree
      3 from .extensions import register_datatree_accessor
      4 from .io import open_datatree

File ~/mambaforge/envs/napari-sparrow/lib/python3.10/site-packages/datatree/datatree.py:33
     31 from xarray.core.merge import dataset_update_method
     32 from xarray.core.options import OPTIONS as XR_OPTS
---> 33 from xarray.core.utils import (
     34     Default,
     35     Frozen,
     36     HybridMappingProxy,
     37     _default,
     38     either_dict_or_kwargs,
     39     maybe_wrap_array,
     40 )
     41 from xarray.core.variable import Variable
     43 from . import formatting, formatting_html

ImportError: cannot import name 'HybridMappingProxy' from 'xarray.core.utils'
ArneDefauw commented 18 hours ago

Hi @galib36 , thanks for using sparrow.

There is currently an incompatibility issue between squidpy and spatialdata causing the error you see, related to incompatible xarray versions, see https://github.com/scverse/squidpy/blob/a9a0a0f2bb42452ffd55c7635dd4dd3739de9698/pyproject.toml#L75 and https://github.com/scverse/spatialdata/blob/72dbffdbc1c949b6e1a5c83a52914e3f20b2d581/pyproject.toml#L46

I advice you to install sparrow via the harpy repo https://github.com/saeyslab/harpy, the API is the same as for sparrow.

Follow installation instructions here: https://harpy.readthedocs.io/en/latest/installation.html

Next activate your conda environment:

conda activate harpy

And then in the terminal do:

pip install squidpy==1.6.2
pip install spatialdata==0.2.6

If there are still issues, do not hesitate to reach out!