materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.48k stars 850 forks source link

ValueError: numpy.dtype size changed #3953

Closed ftherrien closed 1 week ago

ftherrien commented 1 month ago

Python version

Python 3.10.12

Pymatgen version

pymatgen-2024.7.18

Operating system version

Ubuntu 22.04.4 LTS

Current behavior

>>> from pymatgen.core import Lattice
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/felixtherrien/envs/ocpenv/lib/python3.10/site-packages/pymatgen/core/__init__.py", line 11, in <module>
    from pymatgen.core.lattice import Lattice
  File "/home/felixtherrien/envs/ocpenv/lib/python3.10/site-packages/pymatgen/core/lattice.py", line 19, in <module>
    from pymatgen.util.coord import pbc_shortest_vectors
  File "/home/felixtherrien/envs/ocpenv/lib/python3.10/site-packages/pymatgen/util/coord.py", line 14, in <module>
    from pymatgen.util import coord_cython
  File "src/pymatgen/util/coord_cython.pyx", line 1, in init pymatgen.util.coord_cython
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

This happens in a fresh environment where I only installed pymatgen pip install pymatgen In that environment the version of numpy is 2.0.1

Expected Behavior

If I install numpy version 1.26.4, the error disapears

Minimal example

from pymatgen.core import Lattice

Relevant files to reproduce this bug

No response

lbluque commented 1 month ago

The issue here seems to be that the build specifies, https://github.com/materialsproject/pymatgen/blob/98c57888cc4f17ef4d8692d777ad0d1806ee7ae9/pyproject.toml#L5

Which wont work with numpy>=2.0.

To fix quickly, downgrade numpy.

To actually support numpy>=2.0, looks like the build system has to use numpy>=2, which should be backward compatible. See: https://numpy.org/devdocs/dev/depending_on_numpy.html#numpy-2-0-specific-advice

DanielYang59 commented 1 week ago

Hi @ftherrien thanks for reporting this. I believe this issue has been resolved by #3894. Can you have another try?

ftherrien commented 1 week ago

Works now. Thanks!