aburrell / apexpy

A Python wrapper for Apex coordinates
MIT License
34 stars 25 forks source link

BUG: Installation problems with numpy 2.0 #134

Open ljlamarche opened 5 months ago

ljlamarche commented 5 months ago

Describe the bug

Recent installations of apexpy in a clean environment appears to succeed, but then fails on import with the traditional fortranapex error.

UserWarning: fortranapex module could not be imported, so apexpy probably won't work.

Based on the traceback (provided below), the problem looks like it may be related to the recent release of numpy 2.0. When installing in a clean environment, pip will automatically try to install the latest version of the numpy as a dependency. If instead I manually install an older version of numpy BEFORE trying to install apexpy, everything works as expected and there are no problems.

pip install numpy==1.26.4
pip install apexpy

There is a numpy migration guide that will likely be useful in adapting apexpy to work with numpy 2.0.

To Reproduce

  1. Create a fresh python environment (python 3.10 used here)
  2. pip install apexpy
  3. In python, import apexpy

Expected behavior

Apexpy should successfully install and be usable from pip.

Traceback

>>> from apexpy import Apex

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "<stdin>", line 1, in <module>
  File "/Users/e30737/miniconda3/envs/py310_test/lib/python3.10/site-packages/apexpy/__init__.py", line 5, in <module>
    from apexpy import fortranapex  # noqa F401
AttributeError: _ARRAY_API not found
fortranapex module could not be imported. apexpy probably won't work. Failed with error: numpy.core.multiarray failed to import
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "<stdin>", line 1, in <module>
  File "/Users/e30737/miniconda3/envs/py310_test/lib/python3.10/site-packages/apexpy/__init__.py", line 11, in <module>
    from apexpy.apex import Apex, ApexHeightError  # noqa F401
  File "/Users/e30737/miniconda3/envs/py310_test/lib/python3.10/site-packages/apexpy/apex.py", line 13, in <module>
    from apexpy import fortranapex as fa
AttributeError: _ARRAY_API not found
/Users/e30737/miniconda3/envs/py310_test/lib/python3.10/site-packages/apexpy/apex.py:15: UserWarning: fortranapex module could not be imported, so apexpy probably won't work.  Make sure you have a gfortran compiler. Failed with error: numpy.core.multiarray failed to import
  warnings.warn("".join(["fortranapex module could not be imported, so ",

Computer

billetd commented 4 months ago

Came here because I also ran into this issue today. Until fixed, it's also possible to just uninstall numpy whilst apexpy is installed, and then reinstall the previous version before 2.0: pip uninstall numpy pip install numpy==1.26.4

aburrell commented 3 weeks ago

When fixed, update docs/installation.rst.