Skip to content

Incompatibility with numpy 2.x? #59

Open
@fedarko

Description

@fedarko

From biocore/empress#567. Replicated this issue on Ubuntu.

$ # Pinning python = 3.10 to match the linked Empress issue.
$ mamba create -n iowtest20241210 python=3.10 "numpy >= 2" cython  # installs numpy 2.1.3
$ conda activate iowtest
$ pip install iow  # installs iow 1.0.7
$ python3
Python 3.10.15 (main, Oct  3 2024, 07:27:34) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/marcus/anaconda3/envs/iowtest20241210/lib/python3.10/site-packages/bp/__init__.py", line 8, in <module>
    from ._bp import BP
  File "bp/_bp.pyx", line 1, in init bp._bp
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

I verified that the problem persists with Python 3.9 and numpy 2.0.x:

$ conda deactivate
$ mamba create -n iowtest20241210-py39 python=3.9 "numpy >= 2" cython  # installs numpy 2.0.1
$ conda activate iowtest20241210-py39
$ pip install iow  # installs iow 1.0.7
$ python3
Python 3.9.20 (main, Oct  3 2024, 07:27:41) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/marcus/anaconda3/envs/iowtest20241210-py39/lib/python3.9/site-packages/bp/__init__.py", line 8, in <module>
    from ._bp import BP
  File "bp/_bp.pyx", line 1, in init bp._bp
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

The issue can be resolved by downgrading numpy to a version earlier than 2.x:

$ # Still in the iowtest20241210-py39 conda environment.
$ mamba install "numpy < 2"  # installs numpy 1.26.4
$ python3
Python 3.9.20 (main, Oct  3 2024, 07:27:41) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bp
>>> # no error!

... but from what I can tell, iow is intended to support numpy 2.x. Not sure if something has changed upstream recently that breaks things -- figured I should pass this on if you haven't already seen this problem. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions