Can I add a channel to a specific conda environment?

风格不统一 提交于 2020-07-04 08:33:26

问题


I want to add a conda channel to a specific conda environment but when I use

conda config --add channels glotzer

that channel is now available from all my conda environments. In addition to testing an install from another environment, the ~/.condarc file has the following:

channels:
  - glotzer
  - defaults

How would I configure conda so the channel is only available from a specific environment?

I did find in the channel documentation that for conda >= 4.1.0, putting channels at the bottom of the ~/.condarc will prevent added channels from overiding the core package set.

By default conda now prefers packages from a higher priority channel over any version from a lower priority channel. Therefore you can now safely put channels at the bottom of your channel list to provide additional packages that are not in the default channels, and still be confident that these channels will not override the core package set.

I expect this will prevent most problems, except when in one environment you do want the package added through a channel to override a core package.


回答1:


As of conda 4.2, environment-specific .condarc files are supported and you can write:

conda config --env --add channels glotzer

to add the channel to the configuration for the active environment.

[Not sure whether --env flag was added in 4.2. Answer based on conda 4.5.9]




回答2:


Currently it is not possible to add a channel to a single conda environment. If you do not want to add a channel to the global ~/.condarc file, you should use the option to install a package from a specific channel:

conda install <some-package> -c glotzer



回答3:


You can create an environment.yml file containing the specification of your conda environment. The full docs are here, but the basic setup is as follows:

name: EnvironmentName
channels:
    - conda-forge
    - glotzer
dependencies:
    - pip:
        - tensorflow
    - pandas=0.22.*

To use the environment, type

conda env create -f environment.yml
conda activate EnvironmentName

To update the environment when environment.yml is changed or packages are updated,

conda env update -f environment.yml
conda activate EnvironmentName



回答4:


You can create a new environment with a specific channel:

conda create -n EnvironmentName -c ChannelName



来源:https://stackoverflow.com/questions/40616381/can-i-add-a-channel-to-a-specific-conda-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!