在 requirements.txt 中指定依赖项时,如何转义本地 git 存储库路径中的空格



如何在需求中指定本地 git 存储库作为依赖项.txt以便我可以使用pip install -r requirements.txt安装它?问题不在于我无法从该位置安装或克隆,而在于如何在requirements.txt 中转义 repo 目录路径中的空格。需要完全清楚的是,克隆和 pip 安装都通过将路径包含在"中来工作,它只会在pip install -r时失败。

我试过了

  • git+"K:/my/path with/lots of/spaces/repo/.git"

  • git+git://"K:/my/path with/lots of/spaces/repo/.git"

  • git+git:"//K:/my/path with/lots of/spaces/repo/.git"

  • git+"git://K:/my/path with/lots of/spaces/repo/.git"

  • "K:/my/path with/lots of/spaces/repo/.git"

  • git+file://K:/my/path with/lots of/spaces/repo/.git

但是在每种情况下,我都会收到错误ValueError: No closing quotation.

如果我尝试用转义空格,它会被解释为 Windows 路径分隔符并失败。

编辑

所以以下工作:

pip install git+file:///"k/my/path with/lots of/spaces/repo/.git/"

但是,当我将完全相同的东西放入我的requirements.txt中时(当然没有pip install(,我得到了ValueError: No closing quotation.关于如何解决这个问题的任何想法将不胜感激。这是我应该用 pip 打开问题的东西吗?

我在这里引用了用户chrahunt,他在GitHub上回答了这个问题。

当 pip 直接执行时,报价的处理由您的 shell 控制。例如,在 Bash 中,非嵌套的引号对被剥离,它们的内容与之前/之后的内容连接以创建每个参数。

另一方面,需求文件由 optparse 按原样读取,不会发生特殊的报价处理或剥离。

也就是说,在这种情况下,当尝试提供 URL 时,无效的 URL 字符(如空格(必须进行百分比编码(空格为 %20(。

所以就我而言,我不得不更改要求.txt条目git+file:///k/my/path%20with/lots%20of/spaces/repo/.git/并且它起作用了。这不应该依赖于平台,%20 应该在任何地方工作。

最新更新