Lak*_*lla 13 python windows subprocess
详细错误消息:-
\n FileNotFoundError\n\n [WinError 2] The system cannot find the file specified\n\n at ~\\AppData\\Local\\Programs\\Python\\Python39\\lib\\subprocess.py:1582 in _execute_child\n 1578\xe2\x94\x82 sys.audit("subprocess.Popen", executable, args, cwd, env)\n 1579\xe2\x94\x82 \n 1580\xe2\x94\x82 # Start the process\n 1581\xe2\x94\x82 try:\n \xe2\x86\x92 1582\xe2\x94\x82 hp, ht, pid, tid = _winapi.CreateProcess(\n 1583\xe2\x94\x82 executable,\n 1584\xe2\x94\x82 args,\n 1585\xe2\x94\x82 # no special security\n 1586\xe2\x94\x82 None,\nmake: *** [makefile:14: format] Error 1\n\nRun Code Online (Sandbox Code Playgroud)\n我们在这里列出了类似的问题:https ://bugs.python.org/issue17023
\n文件在那里,路径也很好。\n但是为什么我会收到此错误,因为文件位于指定位置?
\n我在运行格式化程序 linter 时收到此错误。
\nIma*_*ras 14
您只需设置shell = True并将其传递给您正在使用的子进程类。修改库文件会导致以后与其他程序员的代码发生兼容性问题。要深入了解为什么我们需要设置此变量,请查看文档: “args 对于所有调用都是必需的,并且应该是字符串或程序参数序列。通常首选提供参数序列,如它允许模块处理任何所需的转义和引用参数(例如,允许文件名中存在空格)。如果传递单个字符串,则 shell 必须为 True(见下文),否则该字符串必须简单地将程序命名为在不指定任何参数的情况下执行。”
Lak*_*lla -3
重要提示:- 如果对库文件进行任何修改,可能会导致以后与其他程序员的代码发生兼容性问题。 要获取更多有关为 shell 设置值的必要性的信息,请参阅官方文档,此处提供了正确的链接。
由于这个错误给我的工作带来了麻烦,我现在做了以下解决方案,一切对我来说都工作正常。
要解决此错误:- 我们必须修改subprocess.py您的环境。
首先,您必须找到该文件,然后对其进行编辑。在我的电脑中,它的位置是 - C:\Users\User\AppData\Local\Programs\Python\Python39\Lib。
在这段代码中:-
def __init__(self, args, bufsize=-1, executable=None,
stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,
shell=True, cwd=None, env=None, universal_newlines=False,
startupinfo=None, creationflags=0,
restore_signals=True, start_new_session=False,
pass_fds=(), *, encoding=None, errors=None):
Run Code Online (Sandbox Code Playgroud)
您必须更改 的值shell。
改成。shell=Falseshell = True
这个解决方案对我有用,我希望它也对你有用。
谢谢。