# 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 ```
Does it function as expected with python3-numpy-f2py installed?
(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
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.
(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?
I've started a discussion upstream here: https://github.com/numpy/numpy/issues/28016
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.
https://src.fedoraproject.org/rpms/numpy/pull-request/49
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?
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
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.