`py -V:X.Y script.py` fails with "No suitable Python runtime found" when script arguments contain forward slashes
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
PC/launcher2.c の parseCommandLine() から始め、次に、記載されている py -V:3.14 コマンドと test_simple.py を Windows 上で使って問題を再現します。バージョンフラグの使用時にスラッシュを含むスクリプト引数が「No suitable Python runtime found」を生成しなくなり、既存の company/tag のパースも引き続き機能すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- cli
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 72/100