python / python/cpython

`py -V:X.Y script.py` fails with "No suitable Python runtime found" when script arguments contain forward slashes

Đang mở Phù hợp với người mới
#148,478 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

3.13 3.14 3.15 interpreter-core OS-windows
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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.exe version: 3.14.4 (C:\Windows\py.EXE)
  • Also present in launcher2.c on main and 3.13 branches (same code)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong PC/launcher2.c tại parseCommandLine(), sau đó tái hiện vấn đề bằng các lệnh py -V:3.14 được liệt kê và test_simple.py trên Windows. Hoàn tất có nghĩa là các đối số script chứa dấu gạch chéo không còn tạo ra “No suitable Python runtime found” khi sử dụng cờ phiên bản, đồng thời việc phân tích company/tag hiện có vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, python
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.