Skip to content

gh-154160: Make sys.executable absolute when resolved from a relative PATH entry#154163

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-gh-154160-sys-executable-relative-path
Open

gh-154160: Make sys.executable absolute when resolved from a relative PATH entry#154163
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-gh-154160-sys-executable-relative-path

Conversation

@fedonman

Copy link
Copy Markdown
Contributor

sys.executable is documented as "a string giving the absolute path of the executable binary for the Python interpreter". When the interpreter is started by a bare program name (no separator) and found through a relative directory in PATH, it was left as that relative path instead:

$ python3 -m venv venv
$ cd /tmp && PATH="venv/bin" python3 -c 'import sys; print(sys.executable)'
venv/bin/python3          # expected an absolute path

getpath absolutizes the executable in the sibling branch that handles a program name containing a separator (executable = abspath(program_name)), but the PATH-resolution loop assigned the joined path directly. This makes it call abspath() there too:

$ cd /tmp && PATH="venv/bin" python3 -c 'import sys; print(sys.executable)'
/tmp/venv/bin/python3

This is a regression from the getpath.c rewrite in 3.11 (bpo-45582 / #29041); 3.10 returned an absolute path.

The issue also notes a separate, cosmetic double-slash case (//usr/local/bin/python3 when invoked as usr/local/bin/python3 from /); that comes from a different branch and is not addressed here.

…lative PATH entry

When the interpreter is started by a bare program name and found through a
relative directory in PATH, getpath left sys.executable as that relative path,
contrary to its documented behaviour of being an absolute path. This is a
regression from the getpath.c rewrite in 3.11.

Absolutize the executable resolved from PATH, matching the sibling branch that
already calls abspath() when the program name itself contains a separator.
@fedonman
fedonman requested a review from FFY00 as a code owner July 19, 2026 15:21
@python-cla-bot

python-cla-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant