はじめに
conda remove --name 環境名 --allで、既存の環境を削除しようとしたら、以下のエラー発生。
$ conda remove --name 環境名 --all
・
・
・
Preparing transaction: done
Verifying transaction: done
Executing transaction: - WARNING conda.core.link:run_script(1098): pre-unlink script failed for package defaults::qt-5.9.5-h02808f3_0
consider notifying the package maintainer
failed
ERROR conda.core.link:_execute(568): An error occurred while uninstalling package 'defaults::qt-5.9.5-h02808f3_0'.
PermissionError(1, 'Operation not permitted')
Attempting to roll back.
Rolling back transaction: done
[Errno 1] Operation not permitted: '/Users/xxxx/anaconda3/envs/環境名/bin/qdbusviewer.app/Contents/PkgInfo' -> '/Users/xxxx/anaconda3/envs/環境名/bin/qdbusviewer.app/Contents/PkgInfo.c~
なぜか環境を削除できず・・・(なぜこのような状況になったのかは不明)
少しはまってしまったので、その時の対処法をメモとして残しておこうと思います。
Anacondaの仮想環境があるフォルダに行って削除!
とりあえず、Anacondaの仮想環境があるディレクトリのbinまで行く
$ cd ~/anaconda3/envs/環境名/bin
そのディレクトリにて、.appを全て消してしまうコマンドを実行
-r: ディレクトリ内を再帰的に削除する
-f: 警告メッセージを表示しない
$ rm -rf *.app
ここまでで準備完了。
そのあと、先ほどのAnacondaの仮想環境を削除するコマンドを実行。
$ conda remove --name 環境名 --all
・
・
・
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: - WARNING conda.core.link:run_script(1098): pre-unlink script failed for package defaults::qt-5.9.5-h02808f3_0
consider notifying the package maintainer
done
WARNINGが出ているけどちゃんと消えたっぽい・・・?
一応以下のコマンドで、環境があるかどうか確認してみます。
$ conda info -e
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
どうやら、すでにカレントディレクトリが存在しないため、コマンドが実行できない、というエラーのよう。
先ほど、~/anaconda3/envs/環境名/bin に移動して、Anacondaの仮想環境を削除してしまったため、
ここではcondaコマンドが使えなくなっているということだと思います。
ルートディレクトリに戻って、同じコマンドを実行すると、きちんと環境削除が完了したことの確認ができました。
conda remove --name 環境名 --all コマンドでなぜ環境が削除できなくなった不明ですが、
最終手段として試してもいいかもしれないです。