問題描述
如何使用另一個 .yml 文件更新預先存在的 conda 環境.這在處理具有多個需求文件的項目時非常有用,例如 base.yml、local.yml、production.yml
等.
How can a pre-existing conda environment be updated with another .yml file. This is extremely helpful when working on projects that have multiple requirement files, i.e. base.yml, local.yml, production.yml
, etc.
例如,下面是一個 base.yml
文件,其中包含 conda-forge、conda 和 pip 包:
For example, below is a base.yml
file has conda-forge, conda, and pip packages:
base.yml
name: myenv
channels:
- conda-forge
dependencies:
- django=1.10.5
- pip:
- django-crispy-forms==1.6.1
實際環境是通過以下方式創建的:conda env create -f base.yml
.
The actual environment is created with:
conda env create -f base.yml
.
稍后,需要將額外的包添加到 base.yml
.另一個文件,比如 local.yml
,需要導入這些更新.
Later on, additional packages need to be added to base.yml
. Another file, say local.yml
, needs to import those updates.
之前的嘗試包括:
使用導入定義創建 local.yml
文件:
creating a local.yml
file with an import definition:
channels:
dependencies:
- pip:
- boto3==1.4.4
imports:
- requirements/base.
然后運行命令:conda install -f local.yml
.
這不起作用.有什么想法嗎?
This does not work. Any thoughts?
推薦答案
嘗試使用 conda 環境更新:
conda activate myenv
conda env update --file local.yml --prune
--prune
卸載從 local.yml
中刪除的依賴項,如 這個答案來自@Blink.
--prune
uninstalls dependencies which were removed from local.yml
, as pointed out in this answer by @Blink.
或者不需要激活環境(感謝@NumesSanguis):
Or without the need to activate the environment (thanks @NumesSanguis):
conda env update --name myenv --file local.yml --prune
請參閱 更新環境 在 Conda 用戶指南中.
See Updating an environment in Conda User Guide.
這篇關于如何使用 .yml 文件更新現有的 Conda 環境的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!