重置 conda 通道优先级

resetting conda channel priorities

我在使用 conda 时遇到问题。在 运行 命令之后,例如:

conda install -c /my_conda_channel numpy --offline --override-channels

默认的 conda 通道现在变成了 'my_conda_channel',因此来自该通道的每个后续包都会取代默认通道,这不是我想要的。我做前者只是为了测试目的。

如何重置频道行为?

转到您的主目录并在编辑器中打开 .condarc。转到 channels 并编辑优先级:

channels:
  - defaults
  - my_conda_channel

现在 defaults 将优先于 my_conda_channel。您还可以删除 my_conda_channel.

更改 ~/.condarc 的顺序,使 defaults 第一个频道为

channels:
  - defaults
  - conda-forge

并添加这一行

channel_priority: true

或运行命令行中的以下代码

conda config --set channel_priority true

然后再运行

conda update --all

祝你好运


针对新版本的 conda 进行了编辑。根据conda doc

As of version 4.6.0, Conda has a strict channel priority feature. Strict channel priority can dramatically speed up conda operations and also reduce package incompatibility problems. We recommend it as a default. However, it may break old environment files, so we plan to delay making it conda's out-of-the-box default until the next major version bump, conda 5.0.

channel_priority (ChannelPriority)
Accepts values of 'strict', 'flexible', and 'disabled'.

它仍然接受旧值 truefalse

  1. true := flexible
  2. false := disabled
  3. strict := 这是一个新值

另一种选择是将您的频道移到优先列表的底部。
运行 命令....

conda config --append channels my_conda_channel

你应该会得到这样的回复...

Warning: 'my_conda_channel' already in 'channels' list, moving to the bottom

验证...

conda config --get channels

哪个应该给你类似...

--add channels 'defaults'   # highest priority
--add channels 'my_conda_channel'   # lowest priority

在环境的 conda-meta 目录中,我添加了一个名为 'pinned':

的文件

固定:

tensorflow               ==2.2.0
tensorflow-base          ==2.2.0
tensorflow-datasets      ==1.2.0
tensorflow-estimator     ==2.2.0

然后,conda update --all 没有更新包:

$ conda update --all
Collecting package metadata (current_repodata.json): - NVIDIA: no NVIDIA devices found
done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.8.4
  latest version: 4.9.1

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /home/ubuntu/anaconda2/envs/ai


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    awscli-1.18.169            |   py36h5fab9bb_0         1.8 MB  conda-forge
    boto3-1.16.9               |     pyhd8ed1ab_0          70 KB  conda-forge
    botocore-1.19.9            |     pyhd3deb0d_0         4.1 MB  conda-forge
    giflib-5.2.1               |       h36c2ea0_2          77 KB  conda-forge
    hypothesis-5.41.0          |     pyhd8ed1ab_0         222 KB  conda-forge
    jpeg-9d                    |       h36c2ea0_0         264 KB  conda-forge
    libpng-1.6.37              |       h21135ba_2         306 KB  conda-forge
    pandas-1.1.4               |   py36hd87012b_0        10.5 MB  conda-forge
    tornado-6.1                |   py36h1d69622_0         644 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        17.9 MB

The following packages will be REMOVED:

  keras-applications-1.0.8-py_1

The following packages will be UPDATED:

  awscli                            1.18.168-py36h5fab9bb_0 --> 1.18.169-py36h5fab9bb_0
  boto3                                 1.16.8-pyhd8ed1ab_0 --> 1.16.9-pyhd8ed1ab_0
  botocore                              1.19.8-pyhd3deb0d_0 --> 1.19.9-pyhd3deb0d_0
  hypothesis                            5.40.0-pyhd8ed1ab_0 --> 5.41.0-pyhd8ed1ab_0
  pandas                               1.1.3-py36h66e3816_2 --> 1.1.4-py36hd87012b_0
  tornado                              6.0.4-py36h8c4c3a4_2 --> 6.1-py36h1d69622_0

The following packages will be DOWNGRADED:

  giflib                                   5.2.1-h516909a_2 --> 5.2.1-h36c2ea0_2
  jpeg                                        9d-h516909a_0 --> 9d-h36c2ea0_0
  libpng                                  1.6.37-hed695b0_2 --> 1.6.37-h21135ba_2


Proceed ([y]/n)? y


Downloading and Extracting Packages
hypothesis-5.41.0    | 222 KB    | ######################################### | 100% 
tornado-6.1          | 644 KB    | ######################################### | 100% 
boto3-1.16.9         | 70 KB     | ######################################### | 100% 
libpng-1.6.37        | 306 KB    | ######################################### | 100% 
awscli-1.18.169      | 1.8 MB    | ######################################### | 100% 
jpeg-9d              | 264 KB    | ######################################### | 100% 
botocore-1.19.9      | 4.1 MB    | ######################################### | 100% 
pandas-1.1.4         | 10.5 MB   | ######################################### | 100% 
giflib-5.2.1         | 77 KB     | ######################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

$ conda list tensorflow
# packages in environment at /home/ubuntu/anaconda2/envs/ai:
#
# Name                    Version                   Build  Channel
tensorflow                2.2.0           mkl_py36h5a57954_0  
tensorflow-base           2.2.0           mkl_py36hd506778_0  
tensorflow-datasets       1.2.0                    py36_0    anaconda
tensorflow-estimator      2.2.0              pyh95af2a2_0    conda-forge
tensorflow-metadata       0.14.0             pyhe6710b0_1  


不幸的是,截至 2021 年 4 月,none 的解决方案对我有用。

有几个 .condarc 文件需要编辑,以确保所需的通道优先级:

  1. ~/.condac。在这里你会发现“全局”频道,这些频道被添加到所有其他手动添加的频道之前(例如 default 频道,或者 conda-forge 在我的例子中以某种方式到达这里,即使我没有手动添加它) . Changing/adding 通过命令行界面的其他频道不会取代此处列出的频道的最高优先级

  2. .condarc anaconda 根目录中的文件。这是手动添加的频道结束的地方(我还会检查 ~/anaconda3/envs/{env_names}/ 环境特定 .condarc 文件)。

如果您想完全控制频道优先级:

  1. 清理 ~/.condarc 文件中的频道部分(顶部)。
  2. 根据所需的通道优先级手动编辑 .condarc 个文件,每个环境(包括基础)一个文件
  3. 设置频道优先级为truestrict
  4. 使用 conda config --show channels
  5. 检查您的编辑结果

您可以按如下方式更改频道优先级:

  1. conda 配置 --get 这将列出优先级从低到高的所有频道
  2. 使用添加频道 conda config --add channels ---(你的频道) 您添加的最后一个频道获得最高优先级..所以保持顺序。您可以添加频道,即使您已经拥有它们也可以更改优先顺序