python / python/cpython

32-bit Python 3.12.7 subprocess.run() cannot run executables from Windows\System32

未關閉
#125,879 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

OS-windows type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:
PS C:\> py -V:3.12-32 -c "import subprocess; subprocess.run(['ssh'])"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Brecht Machiels\AppData\Local\Programs\Python\Python312-32\Lib\subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Brecht Machiels\AppData\Local\Programs\Python\Python312-32\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Brecht Machiels\AppData\Local\Programs\Python\Python312-32\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified

This does work in the 64-bit Python 3.12.7 (after renaming vcruntime140.dll; see #125872):

PS C:\> py -V:3.12 -c "import subprocess; subprocess.run(['ssh'])"
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command [argument ...]]

I'm assuming that this is because ssh.exe is an ARM executable. Using file in a Git Bash shell:

$ file "C:\Windows\System32\OpenSSH\ssh.exe"
C:\Windows\System32\OpenSSH\ssh.exe: PE32+ executable (console) Aarch64, for MS Windows, 6 sections

Calling an amd64 git does work:

PS C:\> py -V:3.12-32 -c "import subprocess; subprocess.run(['git', 'version'])"
git version 2.47.0.windows.1
$ file "C:\Program Files\Git\cmd\git.exe"
C:\Program Files\Git\cmd\git.exe: PE32+ executable (console) x86-64, for MS Windows, 13 sections
CPython versions tested on:

3.12

Operating systems tested on:

Windows 11 ARM

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

在 Windows 11 ARM 上使用 32 位 Python 3.12 命令重現此故障,然後檢查 Lib/subprocess.py 中 Popen 和 _execute_child 附近的程式碼,尤其是 _winapi.CreateProcess 呼叫。將其與成功的 64 位元和 amd64 Git 情況進行比較;當 subprocess.run(['ssh']) 能夠在回報的組態中啟動 Windows System32 可執行檔時,即視為完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
operating-systems
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。