← Back to list

[SOLVED] cmake: brp-python-bytecompile and python3

Ted James · 2024-04-12 05:13 · 0 claps · 1.0 min read paywalled
#rpm #cpack
Open on Medium ↗

cmake: brp-python-bytecompile and python3

I am trying to create a python3 package using cpack (cmake). For some reason it is failing with a cryptic message:

+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
error: Bad exit status from /var/tmp/rpm-tmp.rt2mTp (%install)
    Bad exit status from /var/tmp/rpm-tmp.rt2mTp (%install)
 ***
CPackRPM:Debug:    - /mnt/source/bin2/_CPack_Packages/Linux/RPM/rpmbuildsource-python.out
CPackRPM:Debug: *** Building target platforms: x86_64
Building for target x86_64
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.mxEjdh
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.rt2mTp
Compiling /mnt/source/bin/_CPack_Packages/Linux/RPM/project-0.0.8-Linux/python/usr/lib/python3/dist-packages/project/__init__.py ...
  File "/usr/lib/python3/dist-packages/project/__init__.py", line 27
    raise ValueError(f"Not a {obj.__class__.__name__} reference")
                                       ^
SyntaxError: invalid syntax

Is there a way to skip brp-python-bytecompile step, or else is there a way to instruct cpack that the python package only target python3.

For reference:

# head -1 source/python/__init__.py
#!/usr/bin/env python3

Solution

There are two solutions:

  1. Rely on the /bin hack
  2. Change the default value for __python

For solution #1, you simply need to use a bin subfolder. Any python bytecompilation which happen in a sub-directory of /bin will not be done:

For solution #2, you simply need to follow:

For cmake the syntax is:

set(CPACK_RPM_SPEC_MORE_DEFINE "%define __python python3")

See also an alternate solution:

Answered By — malat

Answer Checked By — David Goodson (FixIt Volunteer)

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0


메타데이터
post_id
08b13df2f0f3
slug
solved-cmake-brp-python-bytecompile-and-python3-08b13df2f0f3
url
https://medium.com/@fixitblog/solved-cmake-brp-python-bytecompile-and-python3-08b13df2f0f3
canonical_url
https://medium.com/@fixitblog/solved-cmake-brp-python-bytecompile-and-python3-08b13df2f0f3
author_url
https://medium.com/@fixitblog
status
ok
fetched_at
2026-07-24 02:04:39