当我在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
。
我发现了引起问题的原因。它是Python的体系结构版本。
我的Windows是64位。我已经下载了32位和64位的嵌入式版本。 64位版本找到了scp.exe可执行文件,如下所示:
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")
>>>
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'
>>>
我之前安装的Python是64位。对Visual Studio Code中未安装解释器的消息感到困扰,我单击了链接并重新安装了解释器,但是该链接指向32位版本。