Python 我可以将频道添加到特定的 conda 环境吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40616381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I add a channel to a specific conda environment?
提问by Steven C. Howell
I want to add a conda channel to a specific conda environmentbut when I use
我想将 conda 通道添加到特定的conda 环境,但是当我使用
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:
该频道现在可从我的所有 conda 环境中使用。除了从另一个环境测试安装之外,该~/.condarc
文件还具有以下内容:
channels:
- glotzer
- defaults
How would I configure conda so the channel is only available from a specific environment?
我将如何配置 conda 以便该频道只能在特定环境中使用?
I did find in the channel documentationthat for conda >= 4.1.0, putting channels at the bottom of the ~/.condarc
will prevent added channels from overiding the core package set.
我确实在频道文档中发现,对于 conda >= 4.1.0,将频道放在底部~/.condarc
会阻止添加的频道覆盖核心包集。
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.
默认情况下,conda 现在更喜欢来自较高优先级频道的包,而不是来自较低优先级频道的任何版本。因此,您现在可以安全地将频道放在频道列表的底部,以提供不在默认频道中的附加包,并且仍然确信这些频道不会覆盖核心包集。
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.
我希望这可以防止大多数问题,除非在一个环境中您确实希望通过渠道添加的包覆盖核心包。
回答by Christopher Barber
As of conda 4.2, environment-specific .condarc
files are supported and you can write:
从 conda 4.2 开始,.condarc
支持特定于环境的文件,您可以编写:
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]
[不确定是否--env
在 4.2 中添加了标志。基于 conda 4.5.9 的答案]
回答by Steven C. Howell
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 环境添加通道。如果您不想向全局~/.condarc
文件添加频道,则应使用该选项从特定频道安装软件包:
conda install <some-package> -c glotzer
回答by BallpointBen
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:
您可以创建一个environment.yml
包含conda
环境规范的文件。完整的文档在这里,但基本设置如下:
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,
要在environment.yml
更改或更新包时更新环境,
conda env update -f environment.yml
conda activate EnvironmentName
回答by Tony Shouse
You can create a new environment with a specific channel:
您可以使用特定频道创建新环境:
conda create -n EnvironmentName -c ChannelName
conda create -n EnvironmentName -c ChannelName