Bug 2239427

Summary: numpy is not Python 3.12 compatible
Product: [Fedora] Fedora Reporter: Susi Lehtola <susi.lehtola>
Component: numpyAssignee: Gwyn Ciesla <gwync>
Status: ON_QA --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 39CC: code, cstratak, gwync, mhroncok, mjg, orion, rdieter, sergio, tomspur
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2210209    
Bug Blocks: 2211813, 2225961    

Description Susi Lehtola 2023-09-18 10:42:13 UTC
libcint fails to build in Fedora 39 and rawhide due to a bug in numpy:

2: Test command: /usr/bin/python3.12 "/builddir/build/BUILD/libcint-5.5.0/testsuite/test_3c2e.py" "--quick"
2: Working Directory: /builddir/build/BUILD/libcint-5.5.0/x86_64-redhat-linux-gnu
2: Test timeout computed to be: 10000000
2: Traceback (most recent call last):
2:   File "/builddir/build/BUILD/libcint-5.5.0/testsuite/test_3c2e.py", line 16, in <module>
2:     _cint = numpy.ctypeslib.load_library('libcint', '.')
2:             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2:   File "/usr/lib64/python3.12/site-packages/numpy/ctypeslib.py", line 137, in load_library
2:     from numpy.distutils.misc_util import get_shared_lib_extension
2:   File "/usr/lib64/python3.12/site-packages/numpy/distutils/__init__.py", line 26, in <module>
2:     from . import ccompiler
2:   File "/usr/lib64/python3.12/site-packages/numpy/distutils/ccompiler.py", line 8, in <module>
2:     from distutils import ccompiler
2: ModuleNotFoundError: No module named 'distutils'
2/2 Test #2: cint3c2etest .....................***Failed    0.17 sec

This error is caused by the removal of distutils in Python 3.12; numpy is therefore not Python 3.12 compatible.

Comment 1 Ben Beasley 2023-09-24 11:34:47 UTC
Note that `numpy.distutils` is removed in numpy 1.26 (not yet packaged) on Python 3.12. That is also the first numpy release to *officially* support Python 3.12.

https://numpy.org/doc/stable/reference/distutils_status_migration.html#distutils-status-migration

For now, with numpy 1.24.4, this can be fixed by adding a runtime dependency on setuptools to numpy, since setuptools vendors distutils and provides it for external use. (Adding BuildRequires: %{py3_dist setuptools}) to libcint would also work, but doesn’t seem to be the right approach since this might affect other packages.)

Comment 3 Fedora Update System 2023-09-26 16:16:15 UTC
FEDORA-2023-e1b5f14c24 has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-e1b5f14c24

Comment 4 Fedora Update System 2023-09-27 01:26:14 UTC
FEDORA-2023-e1b5f14c24 has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-e1b5f14c24`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-e1b5f14c24

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 5 Miro Hrončok 2023-09-29 21:44:05 UTC
I've stopped the Fedora 39 update. I am afraid this will break more things than it is fixing. Dependent packages are failing to build in Rawhide (opencv, scipy, ...).



https://koschei.fedoraproject.org/affected-by/python3-numpy?epoch1=1&version1=1.24.4&release1=2.fc39&epoch2=1&version2=1.26.0&release2=1.fc40&collection=f40

Comment 6 Gwyn Ciesla 2023-09-29 21:46:34 UTC
I'm surprised, I did some testing in a copr and it seemed to fix more than it broke.

Comment 7 Miro Hrončok 2023-09-29 21:51:23 UTC
Backporting this commit should fix the immediate problem as reported by this bugzilla: https://github.com/numpy/numpy/commit/00f633b8579878fa058586e3e412a5d0f82027a1

To clarify when I said "more things" I did not necessarily mean "more packages" but rather the amount of work needed to solve a problem. With 1.24 installing setuptools should fix the problem of missing distutils. With 1.26 there is no way to solve missing numpy.distutils easily.

Comment 9 Miro Hrončok 2023-09-29 21:56:39 UTC
At this point of the Fedora 39 release, all numpy-dependent Python packages were either rebuilt successfully or are on their way to a farm upstate. If we make this update, we are forcing several of them to upgrade on very short notice, possibly introducing even more backward-incompatible changes for their dependents. The Final Freeze starts in less than 4 days. My opinion is: Leave Fedora 39 on numpy 1.24, and backport patches if needed (like the one linked above).

Comment 10 Sergio Basto 2023-09-30 05:39:58 UTC
Hi,
After read this bug report, I checked numpy dependencies and we have 362 packages that depends on numpy, reported by find_unblocked_orphans.py script .
Removing numpy.distutils and for distutils now we need install python3-setuptools, it can have impact or not, I don't know .
But this combination confuse me , on python mass-rebuild a saw a few packages with the warning "distutils it will be removed for Python 3.12" , now I think is "just" numpy.distutils that is removed.

On other hand , I already found a fix for package opencv , turn out it was just in detection of numpy that opencv needs numpy.distutils [1].


I also check VirtualBox-server and still builds on rawhide normally with the same warning:
/builddir/build/BUILD/VirtualBox-7.0.10/src/libs/xpcom18a4/python/gen_python_deps.py:123: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.



[1]
https://src.fedoraproject.org/rpms/opencv/blob/fb8443873603132bda5fa8869d067291f1a2dbfc/f/numpy.distutils_removal.patch

Comment 11 Miro Hrončok 2023-09-30 07:58:32 UTC
Sergio,

 - distutils was removed from Python 3.12 since almost the very beginning
 - python3-setuptools provides its own (forked) distutils module -- many Fedora packages depending on distutils were fixed just by adding BuildRequires: python3-setuptools
 - numpy.distutils (depends on distutils, either the one from Python or the one from setuptools) was removed form NumPy 1.26


Hope this explains things.


If you see: ModuleNotFoundError: No module named 'distutils'
Install python3-setuptools.

If you see: ModuleNotFoundError: No module named 'numpy.distutils' 
No idea what to do.

Comment 12 Michael J Gruber 2023-10-31 12:16:16 UTC
(In reply to Miro Hrončok from comment #11)
> Sergio,
> 
>  - distutils was removed from Python 3.12 since almost the very beginning
>  - python3-setuptools provides its own (forked) distutils module -- many
> Fedora packages depending on distutils were fixed just by adding
> BuildRequires: python3-setuptools

Yes, but is this a fix or a "fix", i.e. a hotfix masking the original problem that packages should migrate away from *any* distutils?

>  - numpy.distutils (depends on distutils, either the one from Python or the
> one from setuptools) was removed form NumPy 1.26
> 

It's unfortunate that we didn't have numpy 1.26 during the py 3.12 mass rebuild (due to numpy's release date). For example, current pandas requires numpy<2,>=1.26.0.

Do you consider numpy 1.26 (i.e. a numpy without numpy.distutils) fair game for a F39 update, or should we expect to live with 1.24 for the F39 cycle (and use pip/whatnot)?

Comment 13 Ben Beasley 2023-10-31 12:31:34 UTC
(In reply to Michael J Gruber from comment #12)
> Yes, but is this a fix or a "fix", i.e. a hotfix masking the original
> problem that packages should migrate away from *any* distutils?

I would call it a “fix” rather than a fix, but there are a few projects that have so heavily extended distutils (in ways that don’t map trivially to setuptools) that migrating away is a major project rather than a quick PR. It’s a good idea to at least suggest the idea upstream, though.

Comment 14 Miro Hrončok 2023-10-31 16:30:50 UTC
> Do you consider numpy 1.26 (i.e. a numpy without numpy.distutils) fair game for a F39 update...

I don't.

Comment 15 Sergio Basto 2023-11-01 18:02:28 UTC
I have to admit that maybe is my fault, when I needed to rebuilt opencv in last minute before F39 Release , I confused missing python3-setuptools with missing numpy.distutils .
In my point of view we should consider numpy 1.26 on F39. And why not rebuild the 362 packages that depends on numpy ?

Comment 16 Ben Beasley 2023-11-01 18:09:35 UTC
Besides numpy.distutils going away, the list of breaking changes since numpy 1.24.4 is long: https://numpy.org/doc/stable/release/1.25.0-notes.html#expired-deprecations

That’s a lot to cope with in post-release updates.