pyenv shim leaks all internal paths (including versions/X/bin) into child process $PATH, breaking pyenv activate for downstream tools
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Start with the reproduction using ~/.pyenv/shims/python3 and inspect libexec/pyenv, along with the shim or pyenv-exec path mentioned in the issue. Trace how PATH is assembled before the user's program is execed. Done means the child process sees the caller's original PATH without pyenv internals or versions/X/bin, while pyenv activation and version switching continue to work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Reproduction:
$ env PATH=/usr/bin:/bin ~/.pyenv/shims/python3 -c 'import os; print(os.environ["PATH"])'
/home/xandox/.pyenv/versions/3.13.7/bin:/home/xandox/.pyenv/libexec:/home/xandox/.pyenv/plugins/python-build/bin:/home/xandox/.pyenv/plugins/pyenv-virtualenv/bin:/home/xandox/.pyenv/plugins/pyenv-update/bin:/home/xandox/.pyenv/plugins/pyenv-doctor/bin:/usr/bin:/bin
Expected:
/usr/bin:/bin
The python process should see the $PATH the caller gave it, nothing more. Python locates its own libraries via sys.path; it doesn't need pyenv's internal directories in $PATH, nor even its own versions/X/bin.
Why versions/X/bin is the critical leak:
When any tool captures the python subprocess's $PATH and propagates it back to the parent shell (either literally, or by sourcing a bash script that does export PATH=...), the parent shell ends up with ~/.pyenv/versions/<default-version>/bin sitting in $PATH ahead of ~/.pyenv/shims. This completely defeats pyenv's version-switching mechanism: pyenv activate <env> sets PYENV_VERSION correctly, but which python still resolves to the hardcoded default-version bin directory, not the shim.
Concrete example that tripped us up:
Fish shell + bass plugin (runs a bash helper via command python3 to source bash scripts and export the resulting env back into fish). In a standard config.fish with pyenv init followed by bass source some-env-setup.sh, bass's python helper inherits the polluted $PATH, bash sources the env-setup script, and the final set -gx PATH ... pushed back into fish contains ~/.pyenv/versions/3.13.7/bin. From that point on, pyenv activate myenv appears to work (prompt updates, PYENV_VERSION is set) but python --version still shows 3.13.7.
Same class of problem would affect any python-based wrapper (pipx helpers, setuptools build scripts, subprocess invocations from IDEs/editors) that captures and re-exports $PATH.
Fix suggestion:
Before execing the user's program, the shim (or pyenv-exec) should restore $PATH to what it was when pyenv was first invoked, minus pyenv internals. One way: stash the original $PATH in a variable at the top of libexec/pyenv, then export PATH="$PYENV_ORIGINAL_PATH" just before exec.
- Ngôn ngữ chính
- Shell
- Star
- 45.2k
- Fork
- 3.3k
- Merge trung bình
- 2 ngày 3 phút
- Pull request đã merge (30 ngày)
- 32
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pyenv/pyenv
-
discussion need-feedback type: documentation
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 53/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Refactor boilerplate code in PyPy scriptsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
third-party third-party: python
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
pyenv/pyenv#3497 · 15 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
pyenv/pyenv#3451 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
area: governance priority: low sdd: ready size: s type: task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
voidxpurple/vacant#159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Abdk4Moura/tunlion#1014 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ci-alert
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
icon request
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
PapirusDevelopmentTeam/papirus-icon-theme#4401 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
package-update
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày