`py -V:X.Y script.py` fails with "No suitable Python runtime found" when script arguments contain forward slashes
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Summary
When using the Python Launcher (py.exe) with a version flag (-V:X.Y), any script argument containing a forward slash (e.g. ./output, /tmp, C:/foo) causes exit code 103 ("No suitable Python runtime found"), even though the specified Python version is installed.
Reproduction
# test_simple.py
import sys
print('ran ok, argv:', sys.argv[1:])
py -V:3.14 test_simple.py files # OK
py -V:3.14 test_simple.py ./files # FAIL: "No suitable Python runtime found"
py -V:3.14 test_simple.py --help # OK (no slash)
py -V:3.14 test_simple.py .\files # OK (backslash is fine)
py -V:3.14 test_simple.py /files # FAIL
py -V:3.14 test_simple.py C:/files # FAIL
py test_simple.py ./files # OK (no -V: flag = unaffected)
Root cause
In PC/launcher2.c, parseCommandLine() parses -V:company/tag as follows:
const wchar_t *argStart = wcschr(arg, L':') + 1; // points past ':' in "-V:3.14"
const wchar_t *tagStart = wcschr(argStart, L'/'); // BUG: scans entire remaining cmdline
arg points into the full command-line string (from GetCommandLineW), not just the current token. tail (the whitespace-bounded end of the -V: token) is computed earlier but is not used to bound the wcschr search.
For py -V:3.14 script.py ./files, argStart is "3.14 script.py ./files...". The unbounded wcschr finds the / in ./files, and misparses:
company = "3.14 script.py ." (should be empty)
tag = "files" (should be "3.14")
selectEnvironment then finds no Python matching this bogus company/tag and returns RC_NO_PYTHON.
Fix
Limit the / search to within tail:
const wchar_t *argStart = wcschr(arg, L':') + 1;
// Search for '/' only within the current token boundary
const wchar_t *tagStart = NULL;
for (const wchar_t *p = argStart; p < tail; ++p) {
if (*p == L'/') { tagStart = p; break; }
}
Environment
- Python 3.14.4 (Windows 11, version 25H2)
py.exeversion: 3.14.4 (C:\Windows\py.EXE)- Also present in
launcher2.conmainand3.13branches (same code)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 PC/launcher2.c 中的 parseCommandLine() 開始,然後在 Windows 上使用列出的 py -V:3.14 命令和 test_simple.py 重現此問題。完成的標準是:使用版本旗標時,包含斜線的腳本引數不再產生「No suitable Python runtime found」,同時現有的 company/tag 剖析仍能正常運作。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- cli
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 72/100