requirements.txt 中使用的语法允许来自 github 项目 ( see here ) 的依赖项。 我想使用 conda 并保持需求文件与 pip 兼容(对于其他人),所以我不想使用 yml 环境文件。
有没有办法创建 pip 和 conda 都可以安装的文件?
最佳答案
Is there a way to create a file that both pip and conda could install from?
不,一般情况下不会。这是因为 Conda 还管理非 Python 依赖项(例如,从其他语言编译的动态库),这些东西通常是 PyPI 不提供的。因此,尽管 Conda 可以输出类似 Pip 的 requirements.txt
(即使用 conda list --export
),但某些包是 Conda 特有的。
至于将 GitHub 项目安装到 Conda 环境中,可以使用 Pip 执行的任何操作都可以在 YAML 文件中完成,例如,从引用的问题开始工作:
YAML
name: my_env
channels:
- defaults
dependencies:
- pip
- pip:
- -e git://github.com/mozilla/elasticutils.git#egg=elasticutils
将使用 Pip 安装 GitHub 托管的包。请参阅the Advanced Pip Example在 Conda 存储库中,了解更多示例。
在 Conda 中使用 Pip 要求文件
还可以通过为其创建 YAML 包装器,在 Conda 中间接使用 Pip requirements.txt
。例如,
需求.txt
-e git://github.com/mozilla/elasticutils.git#egg=elasticutils
my_env.yaml
name: my_env
channels:
- defaults
dependencies:
- pip
- pip:
- -r requirements.txt
您可以使用它来创建新的环境:
conda env create -f my_env.yaml
或者更新现有环境:
conda env update -f my_env.yaml
它将使用 Pip 从 GitHub 安装。
关于python - 使用conda时直接链接到requirements.txt中的github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59864503/