From a4f80ce23f2bba93244c577b571b08b345c3d95e Mon Sep 17 00:00:00 2001 From: Romwierz Date: Mon, 7 Sep 2026 18:10:43 +0200 Subject: [PATCH] pyenv-exec: add option to modify python runtime for the called executable The only variables modified are $PYTHONHOME and $LD_LIBRARY_PATH which will allow the executable to use the shared library of the Python version which is selected with pyenv. --- libexec/pyenv-exec | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libexec/pyenv-exec b/libexec/pyenv-exec index d0f6d071..6477d7f9 100755 --- a/libexec/pyenv-exec +++ b/libexec/pyenv-exec @@ -2,7 +2,9 @@ # # Summary: Run an executable with the selected Python version # -# Usage: pyenv exec [arg1 arg2...] +# Usage: pyenv exec [-E|--environment] [arg1 arg2...] +# +# -E Modify Python runtime environment, such as $PYTHONHOME, for the called executable. # # Runs an executable by first preparing PATH so that the selected Python # version's `bin' directory is at the front. @@ -18,9 +20,16 @@ set -e # Provide pyenv completions if [ "$1" = "--complete" ]; then + echo --environment exec pyenv-shims --short fi +unset MODIFY_ENV +if [ "$1" = "-E" ] || [ "$1" = "--environment" ]; then + MODIFY_ENV=true + shift +fi + PYENV_VERSION="$(pyenv-version-name -f)" PYENV_COMMAND="$1" @@ -54,4 +63,8 @@ if [ "${PYENV_BIN_PATH#${PYENV_ROOT}}" != "${PYENV_BIN_PATH}" ]; then # Only add to $PATH for non-system version. export PATH="${PYENV_BIN_PATH}:${PATH}" fi +if [ -n "$MODIFY_ENV" ]; then + export PYTHONHOME="$(pyenv-prefix)" + export LD_LIBRARY_PATH="${PYTHONHOME}/lib:${LD_LIBRARY_PATH}" +fi exec "$PYENV_COMMAND_PATH" "$@"