pip の場合
pip install optuna
で済むが、conda install optuna を実行すると、そんなパッケージはないと怒られる。解決策はすぐに見つけられたが、コマンドの意味がわからなかったので調べた。
機械学習の勉強をしているにもかかわらずかなり道草している。余計な方向に好奇心が向いていることは自覚しているが、気になってしまったものは仕方がない。
- conda コマンドで optuna をインストールする場合
- -c conda-forge って何?
- なぜわざわざチャネルを指定する必要があるのか
- .condarc の default_channels に conda-forge を追加したらちょっとだけ幸せなのでは?
conda コマンドで optuna をインストールする場合
何も考えず以下のコマンドを実行すれば optuna がインストールできる。公式がそう言っていた。
conda install -c conda-forge optuna
-c conda-forge って何?
-c について
以下、conda の Command Reference からの引用。いろいろ書いてあるが、要はインストールしたいパッケージが置かれているチャネルを指定するためのオプションだと理解した。
-c, --channel Additional channel to search for packages. These are URLs searched in the order they are given (including local directories using the 'file://' syntax or simply a path like '/home/conda/mychan' or '../mychan'). Then, the defaults or channels from .condarc are searched (unless --override-channels is given). You can use 'defaults' to get the default packages for conda. You can also use any name and the .condarc channel_alias value will be prepended. The default channel_alias is https://conda.anaconda.org/.
conda install — conda 23.7.3 documentation
conda-forge について
2 万件以上のパッケージが管理されているチャネル。optuna もこの中に含まれる。
なぜわざわざチャネルを指定する必要があるのか
.condarc のデフォルト設定では、conda-forge は default_channels (defaults) として定義されていないことにより、パッケージを探す対象となっていない。よって、-c conda-forge をつける必要がある。
the defaults or channels from .condarc are searched
.condarc の中身はこんな感じ。Anaconda のルートディレクトリにいる。
逆に言うと、オプションをつけなくてもインストールできるパッケージは、defaults として定義されたチャネルで管理されているものだから。 例として、pandas で見てみる。
↓ pandas をインストール後、conda list した結果
pandas 2.0.3 py311hf62ec03_0
この pandas は default_channels である https://repo.anaconda.com/pkgs/main/ の中にいることがわかる。(URL 内ググったら出てくる)
.condarc の default_channels に conda-forge を追加したらちょっとだけ幸せなのでは?
Exactly!!! って感じのことを公式が教えてくれたのでその通りやってみた。
conda config --append channels conda-forge
conda config — conda 23.7.3 documentation
上記コマンド実行後の .condarc
conda install optuna 実行でエラーなくインストールできることを確認した。なるほどね。