Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError when using Numpy 2 #485

Open
mtilda opened this issue Feb 11, 2025 · 0 comments · May be fixed by #486
Open

ImportError when using Numpy 2 #485

mtilda opened this issue Feb 11, 2025 · 0 comments · May be fixed by #486

Comments

@mtilda
Copy link

mtilda commented Feb 11, 2025

Problem

This package is incompatible with Numpy 2 but does not have an upper bound on the Numpy version in pyproject.toml.

"numpy>=1.19.5",

This leads to the following ImportError when importing the package into an environment with Numpy 2.

ImportError while loading conftest '/home/user/repos/Surprise/tests/conftest.py'.
tests/conftest.py:10: in <module>
    from surprise import Dataset, Reader
.venv/lib/python3.12/site-packages/surprise/__init__.py:6: in <module>
    from .prediction_algorithms import (
.venv/lib/python3.12/site-packages/surprise/prediction_algorithms/__init__.py:23: in <module>
    from .algo_base import AlgoBase
.venv/lib/python3.12/site-packages/surprise/prediction_algorithms/algo_base.py:8: in <module>
    from .. import similarities as sims
surprise/similarities.pyx:1: in init surprise.similarities
    """
E   ImportError: numpy.core.multiarray failed to import (auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; use '<void>numpy._import_array' to disable if you are certain you don't need it).

Steps to reproduce

You can reproduce this problem by following these steps.

# Setup a fresh virtual environment
python -m venv .venv
source .venv/bin/activate

# Install this package and its dependencies
pip install .

# Install packages to run rests
pip install pytest pandas

# Run tests (this will fail with the previously mentioned error)
pytest -v

Full package list

The command pip list shows that pip install . grabbed the most recent version of Numpy (2.2.2).

Package         Version
--------------- -----------
iniconfig       2.0.0
joblib          1.4.2
numpy           2.2.2
packaging       24.2
pandas          2.2.3
pip             24.0
pluggy          1.5.0
pytest          8.3.4
python-dateutil 2.9.0.post0
pytz            2025.1
scikit-surprise 1.1.4
scipy           1.15.1
six             1.17.0
tzdata          2025.1

I noticed this problem magically goes away when importing Surprise in Google Collab. Looks like by default Google Collab installs Numpy 1.26.4.

@mtilda mtilda linked a pull request Feb 11, 2025 that will close this issue
@mtilda mtilda changed the title Incompatible with Numpy 2 ImportError when using Numpy 2 Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant