python 报错(deepfilternet)

运行python报错

C:\Users\11430\.conda\envs\py38\python.exe C:/yuyinqquzao/DeepFilterNet/DeepFilterNet/df/enhance.py
2023-09-08 14:24:06 | INFO     | DF | Running on torch 2.0.1+cpu
2023-09-08 14:24:06 | INFO     | DF | Running on host Shadow-Elves
Traceback (most recent call last):
  File "C:/yuyinqquzao/DeepFilterNet/DeepFilterNet/df/enhance.py", line 399, in <module>
    run()
  File "C:/yuyinqquzao/DeepFilterNet/DeepFilterNet/df/enhance.py", line 395, in run
    main(args)
  File "C:/yuyinqquzao/DeepFilterNet/DeepFilterNet/df/enhance.py", line 65, in main
    model, df_state, suffix = init_df(
  File "C:/yuyinqquzao/DeepFilterNet/DeepFilterNet/df/enhance.py", line 166, in init_df
    init_logger(file=log_file, level=log_level, model=model_base_dir)
  File "C:\yuyinqquzao\DeepFilterNet\DeepFilterNet\df\logger.py", line 46, in init_logger
    commit = get_commit_hash()
  File "C:\yuyinqquzao\DeepFilterNet\DeepFilterNet\df\utils.py", line 152, in get_commit_hash
    git_dir = get_git_root()
  File "C:\yuyinqquzao\DeepFilterNet\DeepFilterNet\df\utils.py", line 144, in get_git_root
    return subprocess.check_output(args).strip().decode()
  File "C:\Users\11430\.conda\envs\py38\lib\subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Users\11430\.conda\envs\py38\lib\subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\11430\.conda\envs\py38\lib\subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\11430\.conda\envs\py38\lib\subprocess.py", line 1327, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

报错的代码片段:

def get_git_root():
    """Returns the top level git directory or None if not called within the git repository."""
    try:
        git_local_dir = os.path.dirname(os.path.abspath(__file__))
        args = ["git", "-C", git_local_dir, "rev-parse", "--show-toplevel"]
        return subprocess.check_output(args).strip().decode()
    except subprocess.CalledProcessError:
        return None


def get_commit_hash():
    """Returns the current git commit."""
    try:
        git_dir = get_git_root()
        if git_dir is None:
            return None
        args = ["git", "-C", git_dir, "rev-parse", "--short", "--verify", "HEAD"]
        return subprocess.check_output(args).strip().decode()
    except subprocess.CalledProcessError:
        # probably not in git repo
        return None

请问朋友们,这个问题出在哪了呢?

【以下回答由 GPT 生成】

解决方案:

根据错误信息,看起来报错是由于以下代码段引起的:

git_dir = get_git_root()

这个错误是在执行subprocess.check_output(args)时发生的,根据错误信息,可能是check_output函数无法找到对应的git命令导致的。

为了解决这个问题,你可以尝试以下几个步骤:

步骤 1: 确认Git是否已正确安装 首先确保你的系统中已经正确安装了Git,并且Git的可执行文件所在目录已经被添加到了系统的环境变量PATH中。你可以在命令行中输入git --version来确认Git是否已正确安装。

如果你没有安装Git,请参考以下步骤进行安装:

  • 在Windows上,你可以到Git官方网站(https://git-scm.com/downloads)下载Git的安装程序,并按照提示进行安装。
  • 在Linux上,你可以使用系统的包管理器来安装Git,例如在Ubuntu上你可以运行sudo apt install git来安装Git。
  • 在macOS上,你可以使用Homebrew来安装Git,运行brew install git即可。

步骤 2: 检查环境变量配置 如果确认已经正确安装了Git,那么请检查一下系统的环境变量配置是否正确。请确保Git的可执行文件所在目录已经被添加到了系统的环境变量PATH中。你可以按照以下步骤进行检查:

  • 在Windows上,打开“控制面板” -> “系统” -> “高级系统设置” -> “环境变量”,在“系统变量”中找到名为“Path”的变量,检查其中是否包含了Git的可执行文件所在目录。如果没有,请点击“编辑”按钮,然后添加Git的可执行文件所在目录。
  • 在Linux和macOS上,打开终端,运行以下命令检查环境变量配置:
echo $PATH

确认输出的结果中是否包含了Git的可执行文件所在目录。

如果环境变量配置正确,那么请继续下一步。

步骤 3: 检查DeepFilterNet代码 如果以上步骤都没有解决问题,那么可能是DeepFilterNet代码中对Git的依赖有问题。你可以在代码中找到以下位置:

C:\yuyinqquzao\DeepFilterNet\DeepFilterNet\df\utils.py

打开utils.py文件,找到get_git_root函数。检查这个函数中的代码是否有问题,特别是subprocess.check_output(args)这一行,确认是否有指定正确的git命令路径。

如果以上步骤仍然没有解决问题,那么可能是DeepFilterNet本身存在其他问题,或者是环境配置有误。你可以尝试寻求DeepFilterNet项目的作者或其他有相关经验的开发者的帮助,或者提交一个issue来报告这个问题。

希望以上的解决方案对你有帮助!如果还有任何问题,请随时提问。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^