← 输入框|github.com|刷新
Skip to content

gh-119696: Find the interpreter relative to installed scripts with --enable-relocatable - #162832

Open
itamaro wants to merge 1 commit into
python:mainfrom
itamaro:relocatable-script-shebangs
Open

itamaro wants to merge 1 commit into
python:mainfrom
itamaro:relocatable-script-shebangs

Conversation

@itamaro

@itamaro itamaro commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

The installed idle3, pydoc3 and python-config Python scripts start with #! and the absolute path of the interpreter, so they stop working once the installation is moved. A #! line also can't hold a path that has spaces, and its length is limited.

With --enable-relocatable, these scripts now start with a small /bin/sh wrapper that runs the interpreter by its location relative to the script. python-config.py in the config directory gets the same wrapper when that directory and the bin directory are both under exec_prefix. Where the realpath command is available, the wrapper also follows a symlink to the script. Without the option, the generated scripts are unchanged.

This patch is inspired by python-build-standalone#395 that ships similar wrappers, with the following differences:

  • narrow scope to the 3 makefile-generated scripts
  • drop -- to avoid noise on BusyBox
  • fallback if realpath is unavailable (still fails if run through a symlink without realpath)
  • python-config.py in the installed config dir gets correct ../../../bin/ relative path

Written with assistance from Claude Fable 5.2

…ith --enable-relocatable

The installed idle3, pydoc3 and python-config Python scripts start with
"#!" and the absolute path of the interpreter. That path is wrong once
the installation is moved, and a "#!" line can't hold a path that has
spaces or is too long.

With --enable-relocatable, start them with a /bin/sh wrapper that runs
the interpreter by its location relative to the script. python-config.py
in the config directory gets the same wrapper, when the bin directory is
"bin" in the prefix. Where the realpath command is available, the
wrapper also follows a symlink to the script.

Without the option the generated scripts are unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review build The build process and cross-build type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant