How do I select the Python version when building a RPM from a .spec file on Fedora 35?
The CentOS/RHEL documentation says
Configure the particular Python 3 version in the BuildRequires of the SPEC file to
python36-rpm-macros
,python38-rpm-macros
, orpython39-rpm-macros
.
Fedora only has a python3.9
package and python3-rpm-macros
package.
How can I set the Python version? How can I make this selection portable between Fedora, RHEL, and other Enterprise Linux flavors?
Attempt at solution
%define __python3 /usr/bin/python3.9
%{?fedora:BuildRequires: python3.9}
%{?rhel:BuildRequires: python39-devel}
Is this correct?
This seems to produce a package that behaves well on both Fedora and CentOS Stream 8.
On Fedora, latest Python is used, and on CentOS I get Python 3.9 and the
#!
lines in script get rewritten to use that Python 3.9 automatically.I consider this a success.