python / python/cpython

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

Ouverte Adaptée aux débutants
#148,478 2 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

3.13 3.14 3.15 interpreter-core OS-windows
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

Description

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)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans PC/launcher2.c, au niveau de parseCommandLine(), puis reproduisez le problème avec les commandes py -V:3.14 indiquées et test_simple.py sous Windows. C’est terminé lorsque les arguments de script contenant des barres obliques ne produisent plus « No suitable Python runtime found » lorsqu’un indicateur de version est utilisé, tout en continuant à faire fonctionner l’analyse existante de company/tag.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c, python
Domaine
cli
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
72/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.