问题:如何使用.yml文件更新现有的Conda环境

如何用另一个.yml文件更新先前的conda环境。在具有多个需求文件(例如)的项目上工作时,这非常有用base.yml, local.yml, production.yml

例如,下面是一个base.yml包含conda-forge,conda和pip软件包的文件:

碱基

name: myenv
channels:
  - conda-forge
dependencies:
  - django=1.10.5
  - pip:
    - django-crispy-forms==1.6.1

实际环境是使用创建的 conda env create -f base.yml

稍后,需要将其他软件包添加到中base.yml。另一个文件,例如local.yml,需要导入这些更新。

先前完成此任务的尝试包括:

创建local.yml具有导入定义的文件:

channels:

dependencies:
  - pip:
    - boto3==1.4.4
imports:
  - requirements/base. 

然后运行命令: conda install -f local.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.

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

The actual environment is created with: conda env create -f base.yml.

Later on, additional packages need to be added to base.yml. Another file, say local.yml, needs to import those updates.

Previous attempts to accomplish this include:

creating a local.yml file with an import definition:

channels:

dependencies:
  - pip:
    - boto3==1.4.4
imports:
  - requirements/base. 

And then run the command: conda install -f local.yml.

This does not work. Any thoughts?


回答 0

尝试使用conda env update

conda activate myenv
conda env update --file local.yml

或无需激活环境(感谢@NumesSanguis):

conda env update --name myenv --file local.yml

Try using conda env update:

conda activate myenv
conda env update --file local.yml

Or without the need to activate the environment (thanks @NumesSanguis):

conda env update --name myenv --file local.yml

回答 1

建议的答案部分正确。您需要添加–prune选项,以卸载从environment.yml中删除的软件包。正确的命令:

conda env update -f local.yml --prune

The suggested answer is partially correct. You’ll need to add the –prune option to also uninstall packages that were removed from the environment.yml. Correct command:

conda env update -f local.yml --prune

回答 2

alkamid的答案是正确的,但是我发现如果环境已经处于活动状态,则Conda无法安装新的依赖项。停用环境首先可以解决此问题:

source deactivate;
conda env update -f whatever.yml;
source activate my_environment_name; # Must be AFTER the conda env update line!

alkamid’s answer is on the right lines, but I have found that Conda fails to install new dependencies if the environment is already active. Deactivating the environment first resolves this:

source deactivate;
conda env update -f whatever.yml;
source activate my_environment_name; # Must be AFTER the conda env update line!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。