conda环境下cannot write keep file问题解决

1 问题描述

conda环境下执行如下命令报错:

pip install git+https://github.com/wenet-e2e/wenet.git

错误信息如下:

(pt) PS D:\code\ptcontainer> pip install git+https://github.com/wenet-e2e/wenet.git
Looking in indexes: http://pypi.douban.com/simple/
Collecting git+https://github.com/wenet-e2e/wenet.git
  Cloning https://github.com/wenet-e2e/wenet.git to c:\users\admin\appdata\local\temp\pip-req-build-r5q7hfto
  Running command git clone --filter=blob:none --quiet https://github.com/wenet-e2e/wenet.git 'C:\Users\Admin\AppData\Local\Temp\pip-req-build-r5q7hfto'
  Resolved https://github.com/wenet-e2e/wenet.git to commit bb199477e7796abb5aadf8ac61ed722d8f94e4c0
  Running command git submodule update --init --recursive -q
  fatal: cannot write keep file 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-r5q7hfto/.git/modules/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/modules/examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransform
er/objects/pack/pack-dded9f2d76bacec32d64839e8151f21651dfadd4.keep': Filename too long
  fatal: fetch-pack: invalid index-pack output
  fatal: clone of 'https://github.com/microsoft/Swin-Transformer' into submodule path 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-r5q7hfto/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/examples/pytorch/swin/Swin-Trans
former-Quantization/SwinTransformer' failed
  Failed to clone 'examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransformer'. Retry scheduled
  fatal: cannot write keep file 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-r5q7hfto/.git/modules/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/modules/examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransform
er/objects/pack/pack-dded9f2d76bacec32d64839e8151f21651dfadd4.keep': Filename too long
  fatal: fetch-pack: invalid index-pack output
  fatal: clone of 'https://github.com/microsoft/Swin-Transformer' into submodule path 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-r5q7hfto/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/examples/pytorch/swin/Swin-Trans
former-Quantization/SwinTransformer' failed
  fatal: Failed to recurse into submodule path 'runtime/gpu/tensorrt_fastertransformer/FasterTransformer'
  error: subprocess-exited-with-error

  × git submodule update --init --recursive -q did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git submodule update --init --recursive -q did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
(pt) PS D:\code\ptcontainer> pip install git+https://github.com/wenet-e2e/wenet.git
Looking in indexes: http://pypi.douban.com/simple/
Collecting git+https://github.com/wenet-e2e/wenet.git
  Cloning https://github.com/wenet-e2e/wenet.git to c:\users\admin\appdata\local\temp\pip-req-build-jbrg39xb
  Running command git clone --filter=blob:none --quiet https://github.com/wenet-e2e/wenet.git 'C:\Users\Admin\AppData\Local\Temp\pip-req-build-jbrg39xb'
  Resolved https://github.com/wenet-e2e/wenet.git to commit 86605c33cee16fb58a3acf390a7790cf127455ed
  Running command git submodule update --init --recursive -q
  fatal: cannot write keep file 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-jbrg39xb/.git/modules/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/modules/examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransform
er/objects/pack/pack-e44608ffdc7d80c35357aa4583a0e4329a899f34.keep': Filename too long
  fatal: fetch-pack: invalid index-pack output
  fatal: clone of 'https://github.com/microsoft/Swin-Transformer' into submodule path 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-jbrg39xb/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/examples/pytorch/swin/Swin-Trans
former-Quantization/SwinTransformer' failed
  Failed to clone 'examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransformer'. Retry scheduled
  fatal: cannot write keep file 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-jbrg39xb/.git/modules/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/modules/examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransform
er/objects/pack/pack-12de821fee873dcc6b2fc9b1db72d5b365c4506c.keep': Filename too long
  fatal: fetch-pack: invalid index-pack output
  fatal: clone of 'https://github.com/microsoft/Swin-Transformer' into submodule path 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-jbrg39xb/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/examples/pytorch/swin/Swin-Trans
former-Quantization/SwinTransformer' failed
  Failed to clone 'examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransformer' a second time, aborting
  fatal: Failed to recurse into submodule path 'runtime/gpu/tensorrt_fastertransformer/FasterTransformer'
  error: subprocess-exited-with-error

  × git submodule update --init --recursive -q did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× git submodule update --init --recursive -q did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

2 问题分析

从报错中寻找关键错误信息:

 fatal: cannot write keep file 'C:/Users/Admin/AppData/Local/Temp/pip-req-build-r5q7hfto/.git/modules/runtime/gpu/tensorrt_fastertransformer/FasterTransformer/modules/examples/pytorch/swin/Swin-Transformer-Quantization/SwinTransform
er/objects/pack/pack-dded9f2d76bacec32d64839e8151f21651dfadd4.keep': Filename too long

分析错误可知,写入文件时,超出了windows文件路径长度限制,所以报错

3 问题解决

3.1 方法一:通过组策略编辑器

打开“本地组策略编辑器”(gpedit.msc),导航到“计算机配置” -> “管理模板” -> “系统” -> “文件系统”,然后启用“启用Win32长路径”策略。

conda环境下cannot write keep file问题解决_第1张图片

conda环境下cannot write keep file问题解决_第2张图片

以管理员身份进入命令行,执行如下命令:

git config --system core.longpaths true

conda环境下cannot write keep file问题解决_第3张图片

3.2 方法二:通过注册表编辑器

打开“注册表编辑器”(regedit),导航到 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem,然后将 LongPathsEnabled 的值设置为 1

conda环境下cannot write keep file问题解决_第4张图片

 以管理员身份进入命令行,执行如下命令:

git config --system core.longpaths true

conda环境下cannot write keep file问题解决_第5张图片

再次运行git命令,不再报错,问题解决。

  4 conda环境介绍

Conda是一个开源的包管理器和环境管理系统,用于安装、运行和更新包和其依赖项。它是由Anaconda, Inc.(以前称为Continuum Analytics)创建,用于支持Python程序开发,但它也可以用来管理来自其他语言的包。Conda使得包管理和环境隔离变得简单,对于处理多个项目中的依赖关系和版本控制尤其有用。

7fe216bee95143b88dd373480ba452ee.webp

Conda是一个强大的工具,对于管理复杂的Python项目和环境至关重要。它简化了包管理和环境设置,使得Python开发更加容易和高效。通过使用Conda,开发者可以确保他们的项目在不同机器和操作系统上都能以相同的方式运行,大大提高了项目的可移植性和可复现性。

4.1 Conda的核心概念

  • 包管理:Conda作为包管理器,能够安装、更新和卸载软件包。这些包可能包含Python或其他编程语言的库和应用程序。Conda通过包含所有依赖性的方式来解决包之间的依赖关系问题。

  • 环境管理:Conda允许用户创建隔离的环境,以便在不同的项目之间切换,而不会导致依赖项或版本的冲突。每个环境都有自己的一套独立的安装的软件包。

  • 跨平台:Conda是跨平台的,可以在Windows、macOS和Linux操作系统上运行。这使得在不同操作系统上保持一致的开发和部署环境成为可能。

  • 语言无关性:虽然Conda最初是为Python生态系统设计的,但它实际上是语言无关的,可以管理多种编程语言的软件包。

  • 通道(Channels):Conda软件包可以从所谓的“通道”中获得。这些通道是包存储库,可以是公共的或私有的。Anaconda Cloud提供了许多预建的包,而用户也可以创建自己的通道来托管和分享包。

  • 依赖和兼容性管理:Conda在安装软件包时会自动处理依赖关系和版本控制,确保所有依赖项都兼容,并且不会发生冲突。

4.2 使用Conda的优势

  • 解决依赖性问题:Conda可以自动解决包之间的依赖关系,简化了安装过程。

  • 环境隔离:创建独立的环境可以避免包之间的版本冲突,使得项目更稳定。

  • 易于使用:Conda的命令行界面简单直观,易于学习和使用。

  • 广泛的包支持:Conda支持Python的许多流行库和应用程序。

  • 社区支持:作为一个流行的工具,Conda拥有一个活跃的社区,用户可以从中找到支持和资源。

4.3 Conda环境的创建和管理

  • 创建新环境:使用conda create命令创建一个新环境,可以指定Python版本和所需的包。

  • 激活环境:使用conda activate命令来激活环境。

  • 安装包:在激活的环境中使用conda install命令来安装新的包。

  • 环境列表:使用conda env list来查看所有可用的Conda环境。

  • 移除环境:使用conda env remove命令来移除不再需要的环境。

4.4 应用场景

Conda作为一个强大的包和环境管理工具,广泛应用于需要精确控制依赖和环境的各种软件开发和科学计算领域,主要包括:

  • 数据科学和机器学习项目:由于Conda可以轻松安装和管理各种数据科学和机器学习的库(如NumPy, Pandas, Scikit-learn, TensorFlow, PyTorch等),它成为了这些领域专家的首选工具。

  • 多语言项目:对于涉及Python、R、Ruby、Lua、Scala等多种编程语言的项目,Conda能够有效管理不同语言的依赖和环境,使项目维护变得更加简单。

  • 环境隔离:在需要为不同项目创建隔离的运行环境时,Conda可以创建独立的环境,每个环境具有不同的库和版本,这有助于防止依赖冲突。

  • 跨平台开发:由于Conda支持Windows、macOS和Linux,它允许开发者在不同的操作系统上以一致的方式设置和维护他们的开发环境。

  • 科学研究:在科学研究中,需要使用特定版本的软件和库来重现实验结果。Conda可以确保这些环境的一致性和可复制性。

  • 软件开发:对于需要确保应用程序在特定版本的库上正常运行的开发场景,Conda可以帮助管理和锁定这些依赖。

  • 教育和培训:在教育场景中,Conda可以帮助创建统一的学习环境,确保所有学生都在相同的软件设置下学习。

  • 持续集成/持续部署(CI/CD):在自动化构建和部署流程中,Conda可以用于创建和管理构建环境,确保软件在不同环境中的一致性和可靠性。

4.5 常用命令

Conda 是一个开源的包管理器和环境管理器,广泛用于管理Python环境和包。以下是一些常用的 Conda 命令:

  • 安装 Conda 包:

    • conda install [package-name]: 安装指定的包。
  • 创建和管理环境:

    • conda create --name [env-name]: 创建一个新的环境。
    • conda activate [env-name]: 激活指定环境。
    • conda deactivate: 退出当前环境。
    • conda env list: 列出所有可用的环境。
  • 管理包:

    • conda list: 在当前环境中列出所有已安装的包。
    • conda update [package-name]: 更新指定的包。
    • conda remove [package-name]: 移除指定的包。
  • 搜索包:

    • conda search [package-name]: 搜索可用的包版本。
  • 环境导出和导入:

    • conda env export > environment.yml: 导出当前环境的配置到一个YAML文件。
    • conda env create -f environment.yml: 使用YAML文件创建一个新环境。
  • 更新 Conda:

    • conda update conda: 更新 Conda 到最新版本。
  • 查看 Conda 信息:

    • conda info: 显示关于 Conda 的信息。

你可能感兴趣的:(AI运行环境,conda,gitclone)