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

BUG: remove numpy.f2py from excludedimports #26776

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yanwic
Copy link

@yanwic yanwic commented Jun 21, 2024

We noticed that PyInstaller fails to correctly bundle our application when using SciPy 1.13.1 & NumPy 2.0.0

Scipy ends up trying to import numpy.f2py when using optimize.root_scalar resulting in a runtime ModuleNotFoundError:

Traceback (most recent call last):
  File "numpy_min_reproducible\__init__.py", line 2, in <module>
  File "scipy\__init__.py", line 147, in __getattr__
  File "importlib\__init__.py", line 126, in import_module
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\optimize\__init__.py", line 413, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\optimize\_optimize.py", line 35, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\linalg\__init__.py", line 205, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\linalg\_basic.py", line 13, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\linalg\_decomp.py", line 26, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\_lib\_util.py", line 18, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\_lib\_array_api.py", line 17, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "scipy\_lib\array_api_compat\numpy\__init__.py", line 1, in <module>
  File "numpy\__init__.py", line 372, in __getattr__
ModuleNotFoundError: No module named 'numpy.f2py'

A minimal reproducible script would be the following:

from scipy import optimize
optimize.root_scalar(lambda x: x,x0=1)

Tested with these dependencies:

python = ">=3.10,<3.13"
numpy = "^2.0.0"
pyinstaller = "^6.8.0"
scipy = "^1.13.1"

Scipy 1.13.1 end up trying to import this module, e.g. when using optimize.root_scalar
@rokm
Copy link

rokm commented Jun 23, 2024

For a bit of context (since we've been looking into this over at PyInstaller as well): in numpy 2.0.0, f2py submodule was added to __all__ attribute of the numpy module. Therefore, excluding numpy.f2py in the PyInstaller hook breaks code that performs

from numpy import *

Most notable example of this is array_api_compat.numpy from https://github.com/data-apis/array-api-compat, which is used by scipy as scipy._lib.array_api_compat (as seen in the OP's traceback).

(The same would have happened with numpy.distutils, except it was not added to __all__ due to deprecation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Awaiting a code review
Development

Successfully merging this pull request may close these issues.

None yet

3 participants