biocore / biom-format

The Biological Observation Matrix (BIOM) Format Project
http://biom-format.org
Other
89 stars 95 forks source link

NumPy 2.0 compatibility issue #955

Closed qiyunzhu closed 3 months ago

qiyunzhu commented 4 months ago

@rgommers We still got an error even with NumPy 2.0-compatible h5py and Pandas installed. Could you please help?

How to reproduce the error:

git clone https://github.com/biocore/biom-format.git
cd biom-format
conda create -n biom-dev -c conda-forge python
conda activate biom-dev
pip install numpy==2.0.0rc1 pandas scipy h5py anndata click cython -e .
echo "import biom" | python

The error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/me/biom-format/biom/__init__.py", line 51, in <module>
    from .table import Table
  File "/home/me/biom-format/biom/table.py", line 196, in <module>
    from ._filter import _filter
  File "biom/_filter.pyx", line 1, in init biom._filter
    # -----------------------------------------------------------------------------
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

Installed packages:

Cython-3.0.10 anndata-0.10.7 array_api_compat-1.6 biom-format-2.1.15.dev0 click-8.1.7 h5py-3.11.0 natsort-8.4.0 numpy-2.0.0rc1 packaging-24.0 pandas-2.2.2 python-dateutil-2.9.0.post0 pytz-2024.1 scipy-1.13.0 six-1.16.0 tzdata-2024.1
rgommers commented 4 months ago

pip install numpy==2.0.0rc1 pandas scipy h5py anndata click cython -e .

That is the problem, it will still build against numpy 1.x due to build isolation (add -v to the command and you'll see what is installed at build time).

Instead you want:

pip install numpy==2.0.0rc1 pandas scipy h5py anndata click cython  # install build and runtime deps
pip install -e . --no-build-isolation   # ensure to build against the already installed build deps
qiyunzhu commented 4 months ago

@rgommers Fantastic! It worked. Thanks for the instruction!