mudata icon indicating copy to clipboard operation
mudata copied to clipboard

Import error with anndata 0.10.9 on Python 3.9

Open jkanche opened this issue 1 year ago • 10 comments

Describe the bug Running into an import error, seems like its limited to Python 3.9. Python 3.9 EOL is 2025. Is there a reason why the package only supports 3.10 and above. Atleast thats my understanding here - https://github.com/scverse/mudata/blob/main/pyproject.toml#L8

To Reproduce Install the package version running in one of my github actions here: anndata==0.10.9 mudata==0.2.4 (last version of the package compatible with Python 3.9)

ImportError while importing test module '/home/runner/work/SingleCellExperiment/SingleCellExperiment/tests/test_sce_combine_cols.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_sce_combine_cols.py:9: in <module>
    from mudata import MuData
.tox/default/lib/python3.9/site-packages/mudata/__init__.py:3: in <module>
    from ._core.mudata import MuData
.tox/default/lib/python3.9/site-packages/mudata/_core/mudata.py:21: in <module>
    from anndata._core.aligned_mapping import (
E   ImportError: cannot import name 'AlignedViewMixin' from 'anndata._core.aligned_mapping' (/home/runner/work/SingleCellExperiment/SingleCellExperiment/.tox/default/lib/python3.9/site-packages/anndata/_core/aligned_mapping.py)

Expected behaviour Expected no import errors

System

  • OS: linux
  • Python version: 3.9
  • Versions of libraries involved: anndata==0.10.9 and mudata==0.2.4

jkanche avatar Oct 01 '24 18:10 jkanche

I'll leave it to @gtca to answer the rest but in general, scverse follows https://scientific-python.org/specs/spec-0000/ where Python 3.9 is already EOL and even 3.10 is getting there.

Numpy, Pandas, Scipy, and others are moving at an increasingly pace and we cannot maintain our packages if we don't follow their support schedules.

Zethson avatar Oct 03 '24 14:10 Zethson

Python 3.9 still gets security updates till the end of 2025 - https://devguide.python.org/versions/.

It seems to be inconsistent within the scverse ecosystem since anndata still supports 3.9. I am not suggesting you support Python 3.9, but may be there's better way of setting up dependencies - https://github.com/scverse/mudata/blob/main/pyproject.toml#L26

jkanche avatar Oct 03 '24 16:10 jkanche

Thanks both!

On the consistency: there was a recent discussion on trying to be more aligned with the version support across packages. Broadly speaking, the SPEC 0 seems to be a good rule of thumb.

On the error and dependencies: the pyproject.toml that you linked specifies python >= 3.10 (since v0.3), and there seems to be nothing wrong with requiring newer versions irrespective of what the dependencies can tolerate. With Python 3.9, you won't be able to use the recent NumPy releases either so the timing looks reasonable.

Seems like this experience is also related to anndata changing the related (private) API in 0.10.9 so its previous patch release should already work for you.

gtca avatar Oct 03 '24 21:10 gtca

Regardless of the drop in support for specific Python versions, it's generally good practice to restrict package versions.

For example, the last supported version for Python 3.9 appears to be v0.2.4. However, if you try to install it now, it will attempt to download the most recent release of the anndata package due to the use of >= in the dependencies, as seen here: https://github.com/scverse/mudata/blob/v0.2.4/pyproject.toml#L24.

To avoid compatibility issues, the version should likely be restricted to 0.10.8 if that's the last known version that works with the package.

For reference, I resolved a similar issue in my packages by locking the versions of dependencies that were known to work, as shown here: https://github.com/BiocPy/SingleCellExperiment/pull/47/files (in my case, I used 0.9.2).

jkanche avatar Oct 06 '24 01:10 jkanche

Hello,

I wanted to note that I get the same error when trying to import scvi even with Python version 3.10.12. Do you have any suggestions on how to troubleshoot this?

ImportError: cannot import name 'AlignedViewMixin' from 'anndata._core.aligned_mapping'

Thank you, Julianne

jflusche avatar Apr 03 '25 15:04 jflusche

@jflusche what are your anndata and mudata versions? Please ensure that they are the latest. Also upgrade scvi-tools

Zethson avatar Apr 03 '25 15:04 Zethson

I have anndata version 0.11.3 and mudata version 0.2.3. I have also tried upgrading scvi-tools (I have version 1.3.0).

jflusche avatar Apr 03 '25 15:04 jflusche

The latest mudata version is 0.3.1

https://pypi.org/project/mudata/

Please upgrade it.

Zethson avatar Apr 03 '25 15:04 Zethson

Let me know if that works, @jflusche, we have tried to improve compatibility across versions in the latest releases.

gtca avatar Apr 03 '25 16:04 gtca

That seemed to work for importing scvi! I am now getting an error though when I try to use scvi to load an existing model.

ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'

Is this related? Do you have any suggestions for what version of pandas should work? I currently have version 2.2.3

jflusche avatar Apr 03 '25 18:04 jflusche

I wanted to follow up on how I solved this issue. I downgraded pandas to version 1.5.3. Thanks for your help with the MuData issue!

jflusche avatar Apr 10 '25 16:04 jflusche