2022/07/16 Updated by

Mac arm64: Python (Miniconda)


[Up] Japanese English

Miniconda のアンインストール

おかしくなったときアンインストールするために、その方法をまとめておく。

インストール場所の確認
  $ conda info --base
  /Users/ntita/miniforge3
[ファイルを削除する]
  $ rm -rf /Users/nitta/miniforge3
  $ rm -rf ~/.cond
[Shell Script の初期化ファイルから設定行を削除する]
  ~/.zshrc
  ~/.bash_profile
  の中の conda の設定部分を削除する。

Miniconda のインストール

Python をインストールする方法として、通常は Anaconda を強く推奨する。 しかし、Apple Silicon (M1, Arm64) の CPU を搭載した mac では現時点(2022/07/16)では Anaconda (arm64版とintel版のどちらでも)をインストールしても tensorflow が利用できない。 そこで miniconda を使うことにする。

もしも Anaconda をインストールしてしまったら、miniconda をインストールする前に Anaconda を アンインストールすること。

[Uninstall Anaconda]
  $ conda install anaconda-clean
  $ anaconda-clean --yes
  $ rm -rf ~/anaconda3
  ~/.zshrc や ~/.bash_profile の中の conda の設定部分を削除する。
  「ターミナル」を再起動する。

miniconda のインストール

  1. python をインストールする方法は4種類ある。Mac (Apple Silicon M1, Arm64) の場合は、現時点では miniforge を使うのがよいとのことだ。
  2. Miniconda の GitHub https https://github.com/conda-forge/miniforge から OS X arm64 (Apple Silicon) 用の shell script Miniforge3-MacOSX-arm64.sh をダウンロードする。


  3. 「ターミナル」上から、shell script を実行する。
  4.     $ cd ~/Downloads
        $ /bin/bash Miniforge3-MacOSX-arm64.sh
    
  5. インストーラで、要請に応じて "yes" または (Enterキー) を入力する。途中、ライセンスの more 表示では 「スペースキー」をタ イプすると次のページに進む。
  6. 「ターミナル」上でのMiniforge3-MacOSX-arm64.sh の実行
    arm64@manet Downloads % /bin/bash Miniforge3-MacOSX-arm64.sh    [Enter]
    
    Welcome to Miniforge3 4.12.0-2
    
    In order to continue the installation process, please review the license
    agreement.
    Please, press ENTER to continue
    >>> [Enter]
    Miniforge installer code uses BSD-3-Clause license as stated below.
    
    Binary packages that come with it have their own licensing terms
    and by installing miniforge you agree to the licensing terms of individual
    packages as well. They include different OSI-approved licenses including
    the GNU General Public License and can be found in pkgs/<pkg-name>/info/licenses
    folders.
    
    Miniforge installer comes with a boostrapping executable that is used            ← 途中で "more" と表示されたときはスペースキーを押すと、次に進む。
    when installing miniforge and is deleted after miniforge is installed.
    The bootstrapping executable uses micromamba, cli11, cpp-filesystem,
    curl, c-ares, krb5, libarchive, libev, lz4, nghttp2, openssl, libsolv,
    nlohmann-json, reproc and zstd which are licensed under BSD-3-Clause,
    MIT and OpenSSL licenses. Licenses and copyright notices of these
    projects can be found at the following URL.
    https://github.com/conda-forge/micromamba-feedstock/tree/master/recipe.
    
    =============================================================================
    
    Copyright (c) 2019-2022, conda-forge
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
    
    1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
    
    2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.
    
    3. Neither the name of the copyright holder nor the names of its contributors
    may be used to endorse or promote products derived from this software without
    specific prior written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    
    Do you accept the license terms? [yes|no]
    [no] >>> yes  [Enter]
    
    Miniforge3 will now be installed into this location:
    /Users/nitta/miniforge3
    
      - Press ENTER to confirm the location
      - Press CTRL-C to abort the installation
      - Or specify a different location below
    
    [/Users/nitta/miniforge3] >>> [Enter]
    PREFIX=/Users/nitta/miniforge3
    Unpacking payload ...
    Extracting "python_abi-3.9-2_cp39.tar.bz2"
    Extracting "idna-3.3-pyhd8ed1ab_0.tar.bz2"
    Extracting "six-1.16.0-pyh6c4a22f_0.tar.bz2"
    Extracting "tqdm-4.64.0-pyhd8ed1ab_0.tar.bz2"
    Extracting "urllib3-1.26.9-pyhd8ed1ab_0.tar.bz2"
    Extracting "libzlib-1.2.12-h90dfc92_0.tar.bz2"
    Extracting "cryptography-37.0.2-py39h4cb6239_0.tar.bz2"
    Extracting "xz-5.2.5-h642e427_1.tar.bz2"
    Extracting "wheel-0.37.1-pyhd8ed1ab_0.tar.bz2"
    Extracting "conda-4.12.0-py39h2804cbe_0.tar.bz2"
    Extracting "python-3.9.13-hc596b02_0_cpython.tar.bz2"
    Extracting "pycparser-2.21-pyhd8ed1ab_0.tar.bz2"
    Extracting "pip-22.1.2-pyhd8ed1ab_0.tar.bz2"
    Extracting "colorama-0.4.4-pyh9f0ad1d_0.tar.bz2"
    Extracting "requests-2.27.1-pyhd8ed1ab_0.tar.bz2"
    Extracting "pyopenssl-22.0.0-pyhd8ed1ab_0.tar.bz2"
    Extracting "brotlipy-0.7.0-py39hb18efdd_1004.tar.bz2"
    Extracting "zlib-1.2.12-h90dfc92_0.tar.bz2"
    Extracting "pycosat-0.6.3-py39hb18efdd_1010.tar.bz2"
    Extracting "ca-certificates-2022.5.18.1-h4653dfc_0.tar.bz2"
    Extracting "setuptools-62.3.2-py39h2804cbe_0.tar.bz2"
    Extracting "pysocks-1.7.1-py39h2804cbe_5.tar.bz2"
    Extracting "tzdata-2022a-h191b570_0.tar.bz2"
    Extracting "certifi-2022.5.18.1-py39h2804cbe_0.tar.bz2"
    Extracting "readline-8.1-hedafd6a_0.tar.bz2"
    Extracting "bzip2-1.0.8-h3422bc3_4.tar.bz2"
    Extracting "libffi-3.4.2-h3422bc3_5.tar.bz2"
    Extracting "ncurses-6.3-h07bb92c_1.tar.bz2"
    Extracting "ruamel_yaml-0.15.80-py39h9eb174b_1007.tar.bz2"
    Extracting "cffi-1.15.0-py39h52b1de0_0.tar.bz2"
    Extracting "yaml-0.2.5-h3422bc3_2.tar.bz2"
    Extracting "tk-8.6.12-he1e0b03_0.tar.bz2"
    Extracting "charset-normalizer-2.0.12-pyhd8ed1ab_0.tar.bz2"
    Extracting "openssl-1.1.1o-ha287fd2_0.tar.bz2"
    Extracting "conda-package-handling-1.8.1-py39hb18efdd_1.tar.bz2"
    Extracting "sqlite-3.38.5-h40dfcc0_0.tar.bz2"
    
                                               __
              __  ______ ___  ____ _____ ___  / /_  ____ _
             / / / / __ `__ \/ __ `/ __ `__ \/ __ \/ __ `/
            / /_/ / / / / / / /_/ / / / / / / /_/ / /_/ /
           / .___/_/ /_/ /_/\__,_/_/ /_/ /_/_.___/\__,_/
          /_/
    
    conda-forge/osx-arm64                                       Using cache
    conda-forge/noarch                                          Using cache
    
    Transaction
    
      Prefix: /Users/nitta/miniforge3
    
      Updating specs:
    
       - python==3.9.13=hc596b02_0_cpython
       - bzip2==1.0.8=h3422bc3_4
       - ca-certificates==2022.5.18.1=h4653dfc_0
       - libffi==3.4.2=h3422bc3_5
       - libzlib==1.2.12=h90dfc92_0
       - ncurses==6.3=h07bb92c_1
       - tzdata==2022a=h191b570_0
       - xz==5.2.5=h642e427_1
       - yaml==0.2.5=h3422bc3_2
       - openssl==1.1.1o=ha287fd2_0
       - readline==8.1=hedafd6a_0
       - tk==8.6.12=he1e0b03_0
       - zlib==1.2.12=h90dfc92_0
       - sqlite==3.38.5=h40dfcc0_0
       - charset-normalizer==2.0.12=pyhd8ed1ab_0
       - colorama==0.4.4=pyh9f0ad1d_0
       - idna==3.3=pyhd8ed1ab_0
       - pycparser==2.21=pyhd8ed1ab_0
       - python_abi==3.9=2_cp39
       - six==1.16.0=pyh6c4a22f_0
       - wheel==0.37.1=pyhd8ed1ab_0
       - certifi==2022.5.18.1=py39h2804cbe_0
       - cffi==1.15.0=py39h52b1de0_0
       - pycosat==0.6.3=py39hb18efdd_1010
       - pysocks==1.7.1=py39h2804cbe_5
       - ruamel_yaml==0.15.80=py39h9eb174b_1007
       - setuptools==62.3.2=py39h2804cbe_0
       - tqdm==4.64.0=pyhd8ed1ab_0
       - brotlipy==0.7.0=py39hb18efdd_1004
       - conda-package-handling==1.8.1=py39hb18efdd_1
       - cryptography==37.0.2=py39h4cb6239_0
       - pip==22.1.2=pyhd8ed1ab_0
       - pyopenssl==22.0.0=pyhd8ed1ab_0
       - urllib3==1.26.9=pyhd8ed1ab_0
       - requests==2.27.1=pyhd8ed1ab_0
       - conda==4.12.0=py39h2804cbe_0
    
    
      Package                       Version  Build               Channel                     Size
    ───────────────────────────────────────────────────────────────────────────────────────────────
      Install:
    ───────────────────────────────────────────────────────────────────────────────────────────────
    
      + brotlipy                      0.7.0  py39hb18efdd_1004   conda-forge/osx-arm64     Cached
      + bzip2                         1.0.8  h3422bc3_4          conda-forge/osx-arm64     Cached
      + ca-certificates         2022.5.18.1  h4653dfc_0          conda-forge/osx-arm64     Cached
      + certifi                 2022.5.18.1  py39h2804cbe_0      conda-forge/osx-arm64     Cached
      + cffi                         1.15.0  py39h52b1de0_0      conda-forge/osx-arm64     Cached
      + charset-normalizer           2.0.12  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + colorama                      0.4.4  pyh9f0ad1d_0        conda-forge/noarch        Cached
      + conda                        4.12.0  py39h2804cbe_0      conda-forge/osx-arm64     Cached
      + conda-package-handling        1.8.1  py39hb18efdd_1      conda-forge/osx-arm64     Cached
      + cryptography                 37.0.2  py39h4cb6239_0      conda-forge/osx-arm64     Cached
      + idna                            3.3  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + libffi                        3.4.2  h3422bc3_5          conda-forge/osx-arm64     Cached
      + libzlib                      1.2.12  h90dfc92_0          conda-forge/osx-arm64     Cached
      + ncurses                         6.3  h07bb92c_1          conda-forge/osx-arm64     Cached
      + openssl                      1.1.1o  ha287fd2_0          conda-forge/osx-arm64     Cached
      + pip                          22.1.2  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + pycosat                       0.6.3  py39hb18efdd_1010   conda-forge/osx-arm64     Cached
      + pycparser                      2.21  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + pyopenssl                    22.0.0  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + pysocks                       1.7.1  py39h2804cbe_5      conda-forge/osx-arm64     Cached
      + python                       3.9.13  hc596b02_0_cpython  conda-forge/osx-arm64     Cached
      + python_abi                      3.9  2_cp39              conda-forge/osx-arm64     Cached
      + readline                        8.1  hedafd6a_0          conda-forge/osx-arm64     Cached
      + requests                     2.27.1  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + ruamel_yaml                 0.15.80  py39h9eb174b_1007   conda-forge/osx-arm64     Cached
      + setuptools                   62.3.2  py39h2804cbe_0      conda-forge/osx-arm64     Cached
      + six                          1.16.0  pyh6c4a22f_0        conda-forge/noarch        Cached
      + sqlite                       3.38.5  h40dfcc0_0          conda-forge/osx-arm64     Cached
      + tk                           8.6.12  he1e0b03_0          conda-forge/osx-arm64     Cached
      + tqdm                         4.64.0  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + tzdata                        2022a  h191b570_0          conda-forge/noarch        Cached
      + urllib3                      1.26.9  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + wheel                        0.37.1  pyhd8ed1ab_0        conda-forge/noarch        Cached
      + xz                            5.2.5  h642e427_1          conda-forge/osx-arm64     Cached
      + yaml                          0.2.5  h3422bc3_2          conda-forge/osx-arm64     Cached
      + zlib                         1.2.12  h90dfc92_0          conda-forge/osx-arm64     Cached
    
      Summary:
    
      Install: 36 packages
    
      Total download: 0 B
    
    ───────────────────────────────────────────────────────────────────────────────────────────────
    
    
    Transaction starting
    Linking bzip2-1.0.8-h3422bc3_4
    Linking ca-certificates-2022.5.18.1-h4653dfc_0
    Linking libffi-3.4.2-h3422bc3_5
    Linking libzlib-1.2.12-h90dfc92_0
    Linking ncurses-6.3-h07bb92c_1
    Linking xz-5.2.5-h642e427_1
    Linking yaml-0.2.5-h3422bc3_2
    Linking openssl-1.1.1o-ha287fd2_0
    Linking zlib-1.2.12-h90dfc92_0
    Linking tk-8.6.12-he1e0b03_0
    Linking readline-8.1-hedafd6a_0
    Linking sqlite-3.38.5-h40dfcc0_0
    Linking tzdata-2022a-h191b570_0
    Linking python-3.9.13-hc596b02_0_cpython
    Linking python_abi-3.9-2_cp39
    Linking setuptools-62.3.2-py39h2804cbe_0
    Linking wheel-0.37.1-pyhd8ed1ab_0
    Linking pip-22.1.2-pyhd8ed1ab_0
    Linking six-1.16.0-pyh6c4a22f_0
    Linking pycparser-2.21-pyhd8ed1ab_0
    Linking idna-3.3-pyhd8ed1ab_0
    Linking colorama-0.4.4-pyh9f0ad1d_0
    Linking charset-normalizer-2.0.12-pyhd8ed1ab_0
    Linking tqdm-4.64.0-pyhd8ed1ab_0
    Linking ruamel_yaml-0.15.80-py39h9eb174b_1007
    Linking pysocks-1.7.1-py39h2804cbe_5
    Linking pycosat-0.6.3-py39hb18efdd_1010
    Linking certifi-2022.5.18.1-py39h2804cbe_0
    Linking cffi-1.15.0-py39h52b1de0_0
    Linking conda-package-handling-1.8.1-py39hb18efdd_1
    Linking cryptography-37.0.2-py39h4cb6239_0
    Linking brotlipy-0.7.0-py39hb18efdd_1004
    Linking pyopenssl-22.0.0-pyhd8ed1ab_0
    Linking urllib3-1.26.9-pyhd8ed1ab_0
    Linking requests-2.27.1-pyhd8ed1ab_0
    Linking conda-4.12.0-py39h2804cbe_0
    Transaction finished
    installation finished.
    Do you wish the installer to initialize Miniforge3
    by running conda init? [yes|no]
    [no] >>> yes  [Enter]
    no change     /Users/nitta/miniforge3/condabin/conda
    no change     /Users/nitta/miniforge3/bin/conda
    no change     /Users/nitta/miniforge3/bin/conda-env
    no change     /Users/nitta/miniforge3/bin/activate
    no change     /Users/nitta/miniforge3/bin/deactivate
    no change     /Users/nitta/miniforge3/etc/profile.d/conda.sh
    no change     /Users/nitta/miniforge3/etc/fish/conf.d/conda.fish
    no change     /Users/nitta/miniforge3/shell/condabin/Conda.psm1
    no change     /Users/nitta/miniforge3/shell/condabin/conda-hook.ps1
    no change     /Users/nitta/miniforge3/lib/python3.9/site-packages/xontrib/conda.xsh
    no change     /Users/nitta/miniforge3/etc/profile.d/conda.csh
    modified      /Users/nitta/.zshrc
    
    ==> For changes to take effect, close and re-open your current shell. <==
    
    If you'd prefer that conda's base environment not be activated on startup, 
       set the auto_activate_base parameter to false: 
    
    conda config --set auto_activate_base false
    
    Thank you for installing Miniforge3!
    arm64@manet Downloads % 
    
  7. シェルの初期ファイルを読み込む(または「ターミナル」を再起動する)
  8.     $ source ~/.zshrc
    
  9. Apple の tensorflow-metal PluggableDevice の記述にしたがって、tensorflow-deps をcondaでインストールする。
  10.     $ conda install -c apple tensorflow-deps
    
  11. 仮想python環境を作成する。tensorflow-metal PluggableDevice によればpython のバージョンは 3.8, 3.9 がサポートされているそうだ。
  12.     (base) $ conda create -n myenv python=3.8 jupyter
    
  13. 仮想python環境に切り替えて、必要なパッケージをインストールする。
  14.     (base) $ conda activate myenv
        (myenv) $ pip install numpy
        (myenv) $ pip install matplotlib
        (myenv) $ pip install tensorflow-macos
        (myenv) $ pip install tensorflow-metal
        (myenv) $ pip install --user pygame
        (myenv) $ pip install gym
    
  15. とりあえず、Tensorflow, OpenAI などが動くことは確認できた。