Python即使使用ssh.exe的完整路径,也无法使用subprocess.run在Windows中找到ssh二进制文件

问题描述 投票:2回答:1

当我在powershell中运行scp.exe时,它会显示用法。但是python告诉该文件不存在使用os.path.isfile("C:\\Windows\\System32\\OpenSSH\\scp.exe")测试的文件。我以前所有通过subprocess.run调用scp的脚本都在工作。现在结果为:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Alyson\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\Alyson\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Alyson\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] O sistema não pode encontrar o arquivo especificado

我最近唯一要做的就是安装Windows Update(KB4537759,KB4532693)并将Python从3.7更新到3.8。我什至试图将shell=true传递给subprocess.run

scp existance tests

python windows openssh
1个回答
0
投票

我发现了引起问题的原因。它是Python的体系结构版本。

我的Windows是64位。我已经下载了32位和64位的嵌入式版本。 64位版本找到了scp.exe可执行文件,如下所示:

  • MSC v.1916 32位(Intel):
PS C:\Users\Alyson\Documents\0\Xpriment\python32> .\python                                    Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
>>> import shutil; shutil.which("scp")
>>>
  • MSC v.1916 64位(AMD64):
PS C:\Users\Alyson\Documents\0\Xpriment\python64> .\python                                            Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
>>> import shutil; shutil.which("scp")
'C:\\Windows\\System32\\OpenSSH\\scp.EXE'
>>> 

print of results

我之前安装的Python是64位。对Visual Studio Code中未安装解释器的消息感到困扰,我单击了链接并重新安装了解释器,但是该链接指向32位版本。

© www.soinside.com 2019 - 2024. All rights reserved.