0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSLにおいてconda activateの際に発生したエラーの解決。conda activateが効かない。

Posted at

問題

conda activateコマンドを使ったところ、下記のエラーが発生。

sh
CondaError: Run 'conda init' before 'conda activate'

言う通りにconda initを行ったところ

sh
no change     /home/sophytoeat/anaconda3/condabin/conda
no change     /home/sophytoeat/anaconda3/bin/conda
no change     /home/sophytoeat/anaconda3/bin/conda-env
no change     /home/sophytoeat/anaconda3/bin/activate
no change     /home/sophytoeat/anaconda3/bin/deactivate
no change     /home/sophytoeat/anaconda3/etc/profile.d/conda.sh
no change     /home/sophytoeat/anaconda3/etc/fish/conf.d/conda.fish
no change     /home/sophytoeat/anaconda3/shell/condabin/Conda.psm1
no change     /home/sophytoeat/anaconda3/shell/condabin/conda-hook.ps1
no change     /home/sophytoeat/anaconda3/lib/python3.12/site-packages/xontrib/conda.xsh
no change     /home/sophytoeat/anaconda3/etc/profile.d/conda.csh
no change     /home/sophytoeat/.bashrc
No action taken.

というエラーが発生。

解決策

この問題は、Anacondaの初期化がうまくいっていない場合に発生することがあるらしいです。下記の通りおこなった

1. .bashrc ファイルを確認する

conda init コマンドは通常、~/.bashrc ファイルにCondaの設定を追加します。しかし、何らかの理由でその設定が反映されていない可能性があるそうなので。これを確認して、修正します。

ターミナルで次のコマンドを実行して .bashrc ファイルの内容を確認します。

nano ~/.bashrc

.bashrc の末尾に次のような行があるか確認してください。

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/sophytoeat/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/sophytoeat/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/sophytoeat/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/sophytoeat/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

もし上記のような記述が無い場合は、手動で .bashrc に追加して保存します。

2. nanoエディタを使った貼り付け

上記のコードをコピーして貼り付けます。貼り付けが終了したら、Ctrl + X を押します。これで終了コマンドを呼び出します。
変更を保存するかどうかを尋ねられるので、保存したい場合は Y (Yes)を押します。保存しない場合は N (No)を押します。
保存する場合、ファイル名を確認するプロンプトが表示されます。変更しない場合はそのまま Enter を押して保存します。

次に、.bashrc の設定を再読み込みします。

source ~/.bashrc

その後、再度Conda環境をアクティベートします。

conda activate 

仮想環境に入れました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?