使用fetch命令获取Chromium遇FileNotFoundError,环境变量修复无效求解决
解决Fetch Chromium时的FileNotFoundError: [WinError 2]问题
问题背景
使用fetch命令获取Chromium代码时触发FileNotFoundError: [WinError 2] 系统找不到指定的文件,已尝试添加DEPOT_TOOLS_WIN_TOOLCHAIN系统环境变量但问题未解决。错误栈如下:
[0:00:00] Started. Traceback (most recent call last): File "C:\src\depot_tools\metrics.py", line 301, in print_notice_and_exit yield File "C:\src\depot_tools\gclient.py", line 3495, in <module> sys.exit(main(sys.argv[1:])) File "C:\src\depot_tools\gclient.py", line 3481, in main return dispatcher.execute(OptionParser(), argv) File "C:\src\depot_tools\subcommand.py", line 252, in execute return command(parser, args[1:]) File "C:\src\depot_tools\gclient.py", line 3032, in CMDsync ret = client.RunOnDeps('update', args) File "C:\src\depot_tools\gclient.py", line 2026, in RunOnDeps work_queue.flush(revision_overrides, File "C:\src\depot_tools\gclient_utils.py", line 1016, in flush reraise(e[0], e[1], e[2]) File "C:\src\depot_tools\gclient_utils.py", line 70, in reraise raise value File "C:\src\depot_tools\gclient_utils.py", line 1093, in run self.item.run(*self.args, **self.kwargs) File "C:\src\depot_tools\gclient.py", line 1005, in run self._got_revision = self._used_scm.RunCommand(command, options, args, File "C:\src\depot_tools\gclient_scm.py", line 128, in RunCommand return getattr(self, command)(options, args, file_list) File "C:\src\depot_tools\gclient_scm.py", line 610, in update mirror = self._GetMirror(url, options, revision, revision_ref) File "C:\src\depot_tools\gclient_scm.py", line 1060, in _GetMirror if not self.cache_dir: File "C:\src\depot_tools\gclient_scm.py", line 225, in cache_dir return git_cache.Mirror.GetCachePath() File "C:\src\depot_tools\git_cache.py", line 193, in GetCachePath cachepath = subprocess.check_output( File "C:\src\depot_tools\.cipd_bin\3.8\bin\Lib\subprocess.py", line 415, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "C:\src\depot_tools\.cipd_bin\3.8\bin\Lib\subprocess.py", line 493, in run with Popen(*popenargs, **kwargs) as process: File "C:\src\depot_tools\.cipd_bin\3.8\bin\Lib\subprocess.py", line 858, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\src\depot_tools\.cipd_bin\3.8\bin\Lib\subprocess.py", line 1311, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified Subprocess failed with return code 1.
可行解决方案
检查Git的安装与PATH配置
打开命令提示符执行git --version,若提示找不到命令,说明Git未安装或未加入系统PATH。安装Git时务必勾选「Add Git to PATH」选项,或手动将Git的bin目录(如C:\Program Files\Git\bin)添加至系统环境变量PATH,重启终端后重试。正确配置DEPOT_TOOLS_WIN_TOOLCHAIN变量
该变量需设置为0而非空值:- 右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
- 在「系统变量」区域新建变量,名称为
DEPOT_TOOLS_WIN_TOOLCHAIN,值设为0 - 重启电脑或终端使配置生效
重置depot_tools工具集
进入C:\src\depot_tools目录,依次执行以下命令更新工具到最新版本:git reset --hard git pull使用管理员权限执行命令
右键命令提示符或PowerShell选择「以管理员身份运行」,再执行fetch chromium,避免权限不足导致的文件访问问题。清理缓存并重新初始化
删除C:\src目录下的.gclient和.gclient_entries文件,然后重新执行fetch chromium命令从头初始化。
内容的提问来源于stack exchange,提问作者jevilbutworse
相关产品推荐
相关产品推荐

