【エラー対処】Anacondaをuninstallするためのanaconda-cleanがインストールできない


# はじめに

大学の研究室で、最初Pythonの環境構築が面倒だったので（おい）
Anacondaをmacに直接installだったのですが
やはりpyenv+pyenv-virtualenvや、dockerでのPython環境にしたいと考え
Anacondaをインストールすることにしました。

参考サイトは
[Anaconda3をmacOSから完全にアンインストールする方法](https://weblabo.oscasierra.net/python-anaconda-uninstall-macos/)です。

# エラー発生

以上のサイトを参考にして

```
conda install anaconda-clean
```
を行い、anacondaの関連ファイルを一括削除するパッケージを入れようとすると
以下のエラーが発生しました。


```
 students$ conda install anaconda-clean
Collecting package metadata (repodata.json): done
Solving environment: \ 
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/osx-64::ipython==7.4.0=py37h39e3cac_0
  - defaults/osx-64::idna==2.8=py37_0
  - conda-forge/osx-64::absl-py==0.7.1=py37_0
  - defaults/osx-64::terminado==0.8.1=py37_1
  - defaults/osx-64::pyopenssl==19.0.0=py37_0
  - defaults/osx-64::pytz==2018.9=py37_0
  - defaults/osx-64::locket==0.2.0=py37_1
  - defaults/osx-64::pyodbc==4.0.26=py37h0a44026_0
  - conda-forge/noarch::astor==0.7.1=py_0
  - defaults/osx-64::pexpect==4.6.0=py37_0
  - defaults/osx-64::pkginfo==1.5.0.1=py37_0
  - defaults/osx-64::snowballstemmer==1.2.1=py37_0
  - defaults/osx-64::pyqt==5.9.2=py37h655552a_2
  - defaults/osx-64::pytest-astropy==0.5.0=py37_0
  - defaults/osx-64::pluggy==0.9.0=py37_0
  - defaults/osx-64::mkl-service==1.1.2=py37hfbe908c_5
  - defaults/osx-64::pickleshare==0.7.5=py37_0
  - defaults/osx-64::jdcal==1.4=py37_0
  - conda-forge/noarch::mako==1.1.0=py_0
  - defaults/osx-64::jupyter==1.0.0=py37_7
  - defaults/osx-64::astroid==2.2.5=py37_0
  - defaults/osx-64::python-libarchive-c==2.8=py37_6
  - defaults/osx-64::psutil==5.6.1=py37h1de35cc_0
  - defaults/osx-64::sphinxcontrib-websupport==1.1.0=py37_1
  - defaults/osx-64::ipywidgets==7.4.2=py37_0
  - conda-forge/osx-64::conda-package-handling==1.4.1=py37_0
  - conda-forge/noarch::gast==0.2.2=py_0
  - defaults/osx-64::get_terminal_size==1.0.0=h7520d66_0
  - defaults/osx-64::imageio==2.5.0=py37_0
  - conda-forge/noarch::keras-preprocessing==1.0.9=py_1
  - defaults/osx-64::wrapt==1.11.1=py37h1de35cc_0
  - defaults/osx-64::alabaster==0.7.12=py37_0
  - defaults/osx-64::zict==0.1.4=py37_0
  - defaults/osx-64::filelock==3.0.10=py37_0
  - defaults/osx-64::nose==1.3.7=py37_2
  - defaults/osx-64::itsdangerous==1.1.0=py37_0
  - conda-forge/osx-64::tensorflow-estimator==1.13.0=py37h24bf2e0_0
  - defaults/osx-64::cycler==0.10.0=py37_0
  - defaults/osx-64::numpy-base==1.16.2=py37h6575580_0
  - defaults/osx-64::pip==19.0.3=py37_0
  - defaults/osx-64::pycosat==0.6.3=py37h1de35cc_0
  - defaults/osx-64::nltk==3.4=py37_1
  - defaults/osx-64::appnope==0.1.0=py37_0
  - defaults/osx-64::clyent==1.2.2=py37_1
  - defaults/osx-64::pytables==3.5.1=py37h5bccee9_0
  - defaults/osx-64::conda-build==3.17.8=py37_0
  - defaults/osx-64::conda-verify==3.1.1=py37_0
  - defaults/osx-64::qtconsole==4.4.3=py37_0
  - defaults/osx-64::traitlets==4.3.2=py37_0
  - defaults/osx-64::sortedcontainers==2.1.0=py37_0
  - defaults/osx-64::et_xmlfile==1.0.1=py37_0
  - conda-forge/osx-64::tensorflow==1.13.1=py37_1
  - defaults/osx-64::pycodestyle==2.5.0=py37_0
  - defaults/osx-64::cffi==1.12.2=py37hb5b8e2f_1
  - defaults/osx-64::bottleneck==1.2.1=py37h1d22016_1
  - defaults/osx-64::wcwidth==0.1.7=py37_0
  - defaults/osx-64::mistune==0.8.4=py37h1de35cc_0
  - defaults/osx-64::llvmlite==0.28.0=py37h8c7ce04_0
  - defaults/osx-64::mpmath==1.1.0=py37_0
  - defaults/osx-64::soupsieve==1.8=py37_0
  - defaults/osx-64::pysocks==1.6.8=py37_0
  - defaults/osx-64::pytest-arraydiff==0.3=py37h39e3cac_0
  - defaults/osx-64::pygments==2.3.1=py37_0
  - defaults/osx-64::pandas==0.24.2=py37h0a44026_0
  - defaults/osx-64::statsmodels==0.9.0=py37h1d22016_0
  - defaults/osx-64::scipy==1.2.1=py37h1410ff5_0
  - defaults/osx-64::packaging==19.0=py37_0
  - defaults/osx-64::six==1.12.0=py37_0
  - defaults/osx-64::anaconda-project==0.8.2=py37_0
  - defaults/osx-64::py==1.8.0=py37_0
  - defaults/osx-64::notebook==5.7.8=py37_0
  - defaults/osx-64::colorama==0.4.1=py37_0
  - defaults/osx-64::ipython_genutils==0.2.0=py37_0
  - defaults/osx-64::defusedxml==0.5.0=py37_1
  - defaults/osx-64::babel==2.6.0=py37_0
  - conda-forge/osx-64::pygpu==0.7.6=py37h917ab60_1000
  - defaults/osx-64::chardet==3.0.4=py37_1
  - defaults/osx-64::py-lief==0.9.0=py37h1413db1_2
  - defaults/osx-64::kiwisolver==1.0.1=py37h0a44026_0
  - defaults/osx-64::jupyter_client==5.2.4=py37_0
  - defaults/osx-64::heapdict==1.0.0=py37_2
  - defaults/osx-64::imagesize==1.1.0=py37_0
  - defaults/osx-64::sqlalchemy==1.3.1=py37h1de35cc_0
  - defaults/osx-64::requests==2.21.0=py37_0
  - defaults/osx-64::keyring==18.0.0=py37_0
  - defaults/osx-64::astropy==3.1.2=py37h1de35cc_0
  - conda-forge/osx-64::conda==4.7.11=py37_0
  - defaults/osx-64::jupyterlab==0.35.4=py37hf63ae98_0
  - defaults/osx-64::pycrypto==2.6.1=py37h1de35cc_9
  - defaults/osx-64::ply==3.11=py37_0
  - defaults/osx-64::spyder-kernels==0.4.2=py37_0
  - defaults/osx-64::nbconvert==5.4.1=py37_3
  - defaults/osx-64::bkcharts==0.2=py37_0
  - defaults/osx-64::pytest-doctestplus==0.3.0=py37_0
  - defaults/osx-64::grpcio==1.16.1=py37h044775b_1
  - defaults/osx-64::tqdm==4.31.1=py37_1
  - defaults/osx-64::docutils==0.14=py37_0
  - defaults/osx-64::decorator==4.4.0=py37_1
  - conda-forge/noarch::markdown==3.1.1=py_0
  - defaults/osx-64::h5py==2.9.0=py37h3134771_0
  - defaults/osx-64::sortedcollections==1.1.2=py37_0
  - defaults/osx-64::jupyter_core==4.4.0=py37_0
  - defaults/osx-64::jedi==0.13.3=py37_0
  - defaults/osx-64::sphinx==1.8.5=py37_0
  - defaults/osx-64::qtpy==1.7.0=py37_1
  - defaults/osx-64::pyflakes==2.1.1=py37_0
  - defaults/osx-64::pywavelets==1.0.2=py37h1d22016_0
  - defaults/osx-64::pathlib2==2.3.3=py37_0
  - defaults/osx-64::click==7.0=py37_0
  - defaults/osx-64::numpy==1.16.2=py37hacdab7b_0
  - defaults/osx-64::pyrsistent==0.14.11=py37h1de35cc_0
  - defaults/osx-64::openpyxl==2.6.1=py37_1
  - defaults/osx-64::numba==0.43.1=py37h6440ff4_0
  - defaults/osx-64::bokeh==1.0.4=py37_0
  - defaults/osx-64::future==0.17.1=py37_0
  - defaults/osx-64::python-dateutil==2.8.0=py37_0
  - defaults/osx-64::singledispatch==3.4.0.3=py37_0
  - defaults/osx-64::anaconda-navigator==1.9.7=py37_0
  - defaults/osx-64::pyyaml==5.1=py37h1de35cc_0
  - conda-forge/noarch::termcolor==1.1.0=py_2
  - defaults/osx-64::python.app==2=py37_9
  - defaults/osx-64::fastcache==1.0.2=py37h1de35cc_2
  - conda-forge/osx-64::tensorboard==1.13.1=py37_0
  - defaults/osx-64::gmpy2==2.0.8=py37h6ef4df4_2
  - defaults/osx-64::flask==1.0.2=py37_1
  - defaults/osx-64::backports==1.0=py37_1
  - defaults/osx-64::jupyter_console==6.0.0=py37_0
  - defaults/osx-64::pyparsing==2.3.1=py37_0
  - defaults/osx-64::cryptography==2.6.1=py37ha12b0ac_0
  - defaults/osx-64::partd==0.3.10=py37_1
  - defaults/osx-64::jupyterlab_server==0.2.0=py37_0
  - defaults/osx-64::webencodings==0.5.1=py37_1
  - defaults/osx-64::scikit-image==0.14.2=py37h0a44026_0
  - defaults/osx-64::entrypoints==0.3=py37_0
  - defaults/osx-64::atomicwrites==1.3.0=py37_1
  - defaults/osx-64::bitarray==0.8.3=py37h1de35cc_0
  - defaults/osx-64::numexpr==2.6.9=py37h7413580_0
  - defaults/osx-64::cython==0.29.6=py37h0a44026_0
  - defaults/osx-64::appscript==1.1.0=py37h1de35cc_0
  - defaults/osx-64::xlwt==1.3.0=py37_0
  - defaults/osx-64::zipp==0.3.3=py37_1
  - defaults/osx-64::dask==1.1.4=py37_1
  - defaults/osx-64::glob2==0.6=py37_1
  - defaults/osx-64::toolz==0.9.0=py37_0
  - defaults/osx-64::qtawesome==0.5.7=py37_1
  - defaults/osx-64::xlrd==1.2.0=py37_0
  - defaults/osx-64::isort==4.3.16=py37_0
  - defaults/osx-64::backports.os==0.1.1=py37_0
  - defaults/osx-64::asn1crypto==0.24.0=py37_0
  - defaults/osx-64::pycurl==7.43.0.2=py37ha12b0ac_0
  - defaults/osx-64::pillow==5.4.1=py37hb68e598_0
  - defaults/osx-64::mkl_random==1.0.2=py37h27c97d8_0
  - defaults/osx-64::xlsxwriter==1.1.5=py37_0
  - defaults/osx-64::simplegeneric==0.8.1=py37_2
  - defaults/osx-64::beautifulsoup4==4.7.1=py37_1
  - defaults/osx-64::bleach==3.1.0=py37_0
  - defaults/osx-64::olefile==0.46=py37_0
  - defaults/osx-64::widgetsnbextension==3.4.2=py37_0
  - defaults/osx-64::wheel==0.33.1=py37_0
  - defaults/osx-64::prometheus_client==0.6.0=py37_0
  - defaults/osx-64::html5lib==1.0.1=py37_0
  - defaults/osx-64::werkzeug==0.14.1=py37_0
  - defaults/osx-64::seaborn==0.9.0=py37_0
  - defaults/osx-64::rope==0.12.0=py37_0
  - defaults/osx-64::mkl_fft==1.0.10=py37h5e564d8_0
  - defaults/osx-64::pytest-openfiles==0.3.2=py37_0
  - defaults/osx-64::gevent==1.4.0=py37h1de35cc_0
  - defaults/osx-64::msgpack-python==0.6.1=py37h04f5b5a_1
  - defaults/osx-64::pytest==4.3.1=py37_0
  - defaults/osx-64::contextlib2==0.5.5=py37_0
  - defaults/osx-64::testpath==0.4.2=py37_0
  - defaults/osx-64::ptyprocess==0.6.0=py37_0
  - defaults/osx-64::pytest-remotedata==0.3.1=py37_0
  - conda-forge/osx-64::keras==2.2.4=py37_1
  - defaults/osx-64::markupsafe==1.1.1=py37h1de35cc_0
  - defaults/osx-64::anaconda-client==1.7.2=py37_0
  - defaults/osx-64::sip==4.19.8=py37h0a44026_0
  - defaults/osx-64::pylint==2.3.1=py37_0
  - defaults/osx-64::wurlitzer==1.0.2=py37_0
  - conda-forge/noarch::keras-applications==1.0.7=py_1
  - defaults/osx-64::patsy==0.5.1=py37_0
  - defaults/osx-64::multipledispatch==0.6.0=py37_0
  - defaults/osx-64::matplotlib==3.0.3=py37h54f8f79_0
  - defaults/osx-64::xlwings==0.15.4=py37_0
  - defaults/osx-64::prompt_toolkit==2.0.9=py37_0
  - conda-forge/osx-64::theano==1.0.4=py37h0a44026_1000
  - defaults/osx-64::ipykernel==5.1.0=py37h39e3cac_0
  - defaults/osx-64::lazy-object-proxy==1.3.1=py37h1de35cc_2
  - defaults/osx-64::parso==0.3.4=py37_0
  - defaults/osx-64::_ipyw_jlab_nb_ext_conf==0.1.0=py37_0
  - conda-forge/osx-64::protobuf==3.9.1=py37h6de7cb9_0
  - defaults/osx-64::unicodecsv==0.14.1=py37_0
  - defaults/osx-64::urllib3==1.24.1=py37_0
  - defaults/osx-64::greenlet==0.4.15=py37h1de35cc_0
  - defaults/osx-64::pycparser==2.19=py37_0
  - defaults/osx-64::spyder==3.3.3=py37_0
  - defaults/osx-64::attrs==19.1.0=py37_1
  - defaults/osx-64::backcall==0.1.0=py37_0
  - defaults/osx-64::anaconda==2019.03=py37_0
  - defaults/osx-64::jinja2==2.10=py37_0
  - defaults/osx-64::mccabe==0.6.1=py37_1
  - conda-forge/osx-64::certifi==2019.6.16=py37_1
  - defaults/osx-64::distributed==1.26.0=py37_1
  - defaults/osx-64::jsonschema==3.0.1=py37_0
  - defaults/osx-64::dask-core==1.1.4=py37_1
  - defaults/osx-64::importlib_metadata==0.8=py37_0
  - defaults/osx-64::sympy==1.3=py37_0
  - defaults/osx-64::numpydoc==0.8.0=py37_0
  - defaults/osx-64::backports.shutil_get_terminal_size==1.0.0=py37_2
  - defaults/osx-64::tblib==1.3.2=py37_0
  - defaults/osx-64::nbformat==4.4.0=py37_0
  - defaults/osx-64::sphinxcontrib==1.0=py37_1
  - defaults/osx-64::cytoolz==0.9.0.1=py37h1de35cc_1
  - defaults/osx-64::more-itertools==6.0.0=py37_0
  - defaults/osx-64::boto==2.49.0=py37_0
  - defaults/osx-64::ruamel_yaml==0.15.46=py37h1de35cc_0
  - defaults/osx-64::python==3.7.3=h359304d_0
  - defaults/osx-64::tornado==6.0.2=py37h1de35cc_0
  - defaults/osx-64::lxml==4.3.2=py37hef8c89e_0
  - defaults/osx-64::pep8==1.7.1=py37_0
  - defaults/osx-64::send2trash==1.5.0=py37_0
  - defaults/osx-64::cloudpickle==0.8.0=py37_0
  - defaults/osx-64::pandocfilters==1.4.2=py37_1
  - defaults/osx-64::pyzmq==18.0.0=py37h0a44026_0
  - defaults/osx-64::path.py==11.5.0=py37_0
  - defaults/osx-64::navigator-updater==0.2.1=py37_0
  - defaults/osx-64::scikit-learn==0.20.3=py37h27c97d8_0
done

## Package Plan ##

  environment location: /anaconda3

  added / updated specs:
    - anaconda-clean


The following NEW packages will be INSTALLED:

  _anaconda_depends  pkgs/main/osx-64::_anaconda_depends-2019.03-py37_0
  anaconda-clean     pkgs/main/osx-64::anaconda-clean-1.1.0-py37_1
  networkx           pkgs/main/noarch::networkx-2.3-py_0
  setuptools         pkgs/main/osx-64::setuptools-41.0.1-py37_0
  tbb                pkgs/main/osx-64::tbb-2019.4-h04f5b5a_0

The following packages will be UPDATED:

  openssl            conda-forge::openssl-1.1.1c-h01d97ff_0 --> pkgs/main::openssl-1.1.1d-h1de35cc_1

The following packages will be SUPERSEDED by a higher-priority channel:

  ca-certificates    conda-forge::ca-certificates-2019.6.1~ --> pkgs/main::ca-certificates-2019.5.15-1

The following packages will be DOWNGRADED:

  anaconda                                   2019.03-py37_0 --> custom-py37_1


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: failed

RemoveError: 'setuptools' is a dependency of conda and cannot be removed from
conda's operating environment.
```

大事なのは下の$2$行

```
RemoveError: 'setuptools' is a dependency of conda and cannot be removed from
conda's operating environment.
```
で、「setuptoolsがcondaに依存しているから、condaの環境から削除できないよう〜」っていう部分です。

おそらく、PyPIにパッケージをインストールしたときにsetuptoolsをいじった記憶があるのでそれの影響が出ているんだと思います。

# 対策方法

まず、Anacondaのcondaをアップデートしないといけないようなので
（PyPI, pipでインストールしてしまったsetuptoolsを依存を治す意図？）

```
 conda update --force conda
```

で強制アップデートします。

その後

```
conda install -c anaconda setuptools
```

でsetuptoolsをインスコします。

そして、最後に

```
conda install anaconda-clean
```

をすると、エラーが消えました。
うれしい！