Bug 2332307 - No module named 'numpy.f2py' exception on python3-numpy-1:2.2.0-1.fc42.x86_64
Summary: No module named 'numpy.f2py' exception on python3-numpy-1:2.2.0-1.fc42.x86_64
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: numpy
Version: rawhide
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Gwyn Ciesla
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: NUMPY2
TreeView+ depends on / blocked
 
Reported: 2024-12-13 17:54 UTC by Even Rouault
Modified: 2024-12-18 15:13 UTC (History)
4 users (show)

Fixed In Version: numpy-2.2.0-3.fc42
Clone Of:
Environment:
Last Closed: 2024-12-18 15:13:48 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github numpy numpy issues 28016 0 None open BUG: make f2py an optional sub-module again 2024-12-17 04:41:32 UTC

Description Even Rouault 2024-12-13 17:54:33 UTC
# python3 -c "from numpy import *"

triggers the following exception:

```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from numpy import *
  File "/usr/lib64/python3.13/site-packages/numpy/__init__.py", line 361, in __getattr__
    import numpy.f2py as f2py
ModuleNotFoundError: No module named 'numpy.f2py'
```



Reproducible: Always



Expected Results:  
no exception

```
# dnf install python3-numpy
Updating and loading repositories:
Repositories loaded.
Package                                                              Arch            Version                                                              Repository                                   Size
Installing:
 python3-numpy                                                       x86_64          1:2.2.0-1.fc42                                                       rawhide                                  40.8 MiB
Installing dependencies:
 flexiblas                                                           x86_64          3.4.4-3.fc41                                                         rawhide                                  48.5 KiB
 flexiblas-netlib                                                    x86_64          3.4.4-3.fc41                                                         rawhide                                  10.7 MiB
 flexiblas-openblas-openmp                                           x86_64          3.4.4-3.fc41                                                         rawhide                                  43.3 KiB
 libgfortran                                                         x86_64          14.2.1-6.fc42                                                        rawhide                                   3.0 MiB
 libquadmath                                                         x86_64          14.2.1-6.fc42                                                        rawhide                                 325.9 KiB
 openblas                                                            x86_64          0.3.28-2.fc42                                                        rawhide                                 106.6 KiB
 openblas-openmp                                                     x86_64          0.3.28-2.fc42                                                        rawhide                                  39.3 MiB
```

Comment 1 Gwyn Ciesla 2024-12-13 18:28:31 UTC
Does it function as expected with python3-numpy-f2py installed?

Comment 2 Even Rouault 2024-12-13 18:35:14 UTC
(In reply to Gwyn Ciesla from comment #1)
> Does it function as expected with python3-numpy-f2py installed?

thanks, yes, it does, although I would consider this more as a workaround than the proper solution. "from numpy import *" is rather idiomatic in a number of use cases, and should work even if optional packages are not installed

Comment 3 Orion Poplawski 2024-12-17 04:06:28 UTC
I'm coming to the opinion that if you want to do 'from numpy import *' - which is not recommended in general because it pollutes the global namespace, you should explicitly require f2py.  Especially as f2py pulls in python3-devel.

I've filed https://src.fedoraproject.org/rpms/python-matplotlib/pull-request/43 for matplotlib.

Comment 4 Even Rouault 2024-12-17 04:19:32 UTC
(In reply to Orion Poplawski from comment #3)
> I'm coming to the opinion that if you want to do 'from numpy import *' -
> which is not recommended in general because it pollutes the global
> namespace, you should explicitly require f2py.  Especially as f2py pulls in
> python3-devel.
> 
> I've filed
> https://src.fedoraproject.org/rpms/python-matplotlib/pull-request/43 for
> matplotlib.

I respectfully disagree. This breaks existing software, namely the gdal_calc utility of GDAL (https://gdal.org) which doesn't need the f2py functionality. Couldn't it be possible to make "from numpy import *" still work and skip importing f2py when it is not available?

Comment 5 Orion Poplawski 2024-12-17 04:41:32 UTC
I've started a discussion upstream here: https://github.com/numpy/numpy/issues/28016

Comment 6 Orion Poplawski 2024-12-18 03:04:32 UTC
So, here are some numbers:

Package                    Arch   Version        Repository      Size
Installing:
 python3-numpy             x86_64 1:2.2.0-1.fc42 fedora      40.8 MiB
Installing dependencies:
 expat                     x86_64 2.6.4-1.fc42   fedora     285.5 KiB
 flexiblas                 x86_64 3.4.4-3.fc41   fedora      48.5 KiB
 flexiblas-netlib          x86_64 3.4.4-3.fc41   fedora      10.7 MiB
 flexiblas-openblas-openmp x86_64 3.4.4-3.fc41   fedora      43.3 KiB
 libb2                     x86_64 0.98.1-12.fc41 fedora      42.2 KiB
 libgfortran               x86_64 14.2.1-6.fc42  fedora       3.0 MiB
 libquadmath               x86_64 14.2.1-6.fc42  fedora     325.9 KiB
 mpdecimal                 x86_64 2.5.1-16.fc41  fedora     204.9 KiB
 openblas                  x86_64 0.3.28-2.fc42  fedora     106.6 KiB
 openblas-openmp           x86_64 0.3.28-2.fc42  fedora      39.3 MiB
 python-pip-wheel          noarch 24.3.1-1.fc42  fedora       1.2 MiB
 python3                   x86_64 3.13.1-2.fc42  fedora      30.6 KiB
 python3-libs              x86_64 3.13.1-2.fc42  fedora      39.8 MiB
 tzdata                    noarch 2024b-1.fc42   fedora       1.6 MiB

Package                 Arch   Version        Repository      Size
Installing:
 python3-numpy-f2py     x86_64 1:2.2.0-1.fc42 fedora       2.0 MiB
Installing dependencies:
 pyproject-rpm-macros   noarch 1.16.3-1.fc42  fedora     113.7 KiB
 python-rpm-macros      noarch 3.13-3.fc41    fedora      22.1 KiB
 python3-devel          x86_64 3.13.1-2.fc42  fedora       1.8 MiB
 python3-packaging      noarch 24.2-2.fc42    fedora     555.7 KiB
 python3-rpm-generators noarch 14-11.fc41     fedora      81.7 KiB
 python3-rpm-macros     noarch 3.13-3.fc41    fedora       6.4 KiB

I now think the additional deps are small enough compared to the size of the main package and its deps that it probably isn't worth splitting out anymore, especially since upstream is not inclined to support it.

Comment 8 Orion Poplawski 2024-12-18 14:55:20 UTC
The above PR adds a requires on f2py, which seems like the simplest was forward for now.

If we were to do a downstream patch to allow splitting out f2py, my first thought would be something like:

diff --git a/numpy/__init__.py b/numpy/__init__.py
index 67db9bcaf7..d28a2c3cd0 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -357,8 +357,11 @@ def __getattr__(attr):
             import numpy.matlib as matlib
             return matlib
         elif attr == "f2py":
-            import numpy.f2py as f2py
-            return f2py
+            try:
+                import numpy.f2py as f2py
+                return f2py
+            except ImportError:
+                return None
         elif attr == "typing":
             import numpy.typing as typing
             return typing

But that does seem like it could trigger some odd errors with f2py being unexpectedly None. Any other suggestions?

Comment 9 Fedora Update System 2024-12-18 15:09:23 UTC
FEDORA-2024-0c4e6fc939 (numpy-2.2.0-3.fc42) has been submitted as an update to Fedora 42.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-0c4e6fc939

Comment 10 Fedora Update System 2024-12-18 15:13:48 UTC
FEDORA-2024-0c4e6fc939 (numpy-2.2.0-3.fc42) has been pushed to the Fedora 42 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.