2021年5月8日土曜日

macOSのPython3にNumPy, SciPy, matplotlibをインストールする.

macOSに付属していたPython 2では NumPy, SciPy, matplotlib がプリインストールされていました.一方で,Python 3にはそれらがインストールされていないため,別途インストールが必要です.

インストールする際には,ターミナルで以下のようなコマンドを実行します.

まずは,NumPyのインストールです.

% python3 -m pip install --upgrade numpy

python3 -m pip install コマンドを使って,NumPyをインストールします.
--upgrade オプションをつけると,古いバージョンがインストールされている場合には,新しいバージョンに更新されます.
以下は,上記のコマンドを実行した結果です.

Requirement already satisfied: numpy in /usr/local/lib/python3.9/site-packages (1.20.2)

Collecting numpy

  Downloading numpy-1.21.5-cp39-cp39-macosx_10_9_x86_64.whl (17.0 MB)

     |████████████████████████████████| 17.0 MB 915 kB/s 

Installing collected packages: numpy

  Attempting uninstall: numpy

    Found existing installation: numpy 1.20.2

    Uninstalling numpy-1.20.2:

      Successfully uninstalled numpy-1.20.2

Successfully installed numpy-1.21.5

次にSciPyのインストールです.実行するコマンドは以下です.

% python3 -m pip install --upgrade scipy

すると,以下のようにインストールが実行されます.

Collecting scipy

  Downloading scipy-1.7.3-cp39-cp39-macosx_10_9_x86_64.whl (33.2 MB)

     |████████████████████████████████| 33.2 MB 1.2 MB/s 

Requirement already satisfied: numpy<1.23.0,>=1.16.5 in /usr/local/lib/python3.9/site-packages (from scipy) (1.21.5)

Installing collected packages: scipy

Successfully installed scipy-1.7.3

最後にmatplotlibのインストールです.実行するコマンドは以下です.

python3 -m pip install --upgrade matplotlib

そうすると,インストールが始まります.

Requirement already satisfied: matplotlib in /usr/local/lib/python3.9/site-packages (3.4.2)

Collecting matplotlib

  Downloading matplotlib-3.5.1-cp39-cp39-macosx_10_9_x86_64.whl (7.3 MB)

     |████████████████████████████████| 7.3 MB 1.2 MB/s 

Collecting fonttools>=4.22.0

  Downloading fonttools-4.28.5-py3-none-any.whl (890 kB)

     |████████████████████████████████| 890 kB 1.2 MB/s 

Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.9/site-packages (from matplotlib) (0.10.0)

Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.9/site-packages (from matplotlib) (20.9)

Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.9/site-packages (from matplotlib) (2.4.7)

Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.9/site-packages (from matplotlib) (2.8.1)

Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.9/site-packages (from matplotlib) (1.21.5)

Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.9/site-packages (from matplotlib) (8.2.0)

Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/site-packages (from matplotlib) (1.3.1)

Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from cycler>=0.10->matplotlib) (1.15.0)

Installing collected packages: fonttools, matplotlib

  Attempting uninstall: matplotlib

    Found existing installation: matplotlib 3.4.2

    Uninstalling matplotlib-3.4.2:

      Successfully uninstalled matplotlib-3.4.2

Successfully installed fonttools-4.28.5 matplotlib-3.5.1


ちなみに,Seabornもデフォルトではインストールされていないので,別途インストールするには,以下のようになります.

hide@MBP ~ % pip3 install seaborn

Collecting seaborn

  Using cached seaborn-0.11.2-py3-none-any.whl (292 kB)

Requirement already satisfied: pandas>=0.23 in /usr/local/lib/python3.9/site-packages (from seaborn) (1.2.4)

Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.9/site-packages (from seaborn) (1.21.5)

Requirement already satisfied: matplotlib>=2.2 in /usr/local/lib/python3.9/site-packages (from seaborn) (3.5.1)

Requirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.9/site-packages (from seaborn) (1.7.3)

Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (2.8.1)

Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (8.2.0)

Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (1.3.1)

Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (20.9)

Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (2.4.7)

Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (0.10.0)

Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.9/site-packages (from matplotlib>=2.2->seaborn) (4.28.5)

Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from cycler>=0.10->matplotlib>=2.2->seaborn) (1.15.0)

Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.9/site-packages (from pandas>=0.23->seaborn) (2021.1)

Installing collected packages: seaborn

Successfully installed seaborn-0.11.2


-----
pipコマンドを使ってインストールする際に以下のような警告が出る場合があります.

WARNING: You are using pip version 21.0.1; however, version 21.3.1 is available.

You should consider upgrading via the '/opt/homebrew/opt/python@3.9/bin/python3.9 -m pip install --upgrade pip' command.


/opt/homebrew/opt/python@3.9/bin/は,Python3(この場合は ver. 3.9)のインストールされている場所なので,環境によって異なります.
警告はpipを最新にするようにというないようなので,以下のように実行しておきます.

% /opt/homebrew/opt/python@3.9/bin/python3.9 -m pip install --upgrade pip

Requirement already satisfied: pip in /opt/homebrew/lib/python3.9/site-packages (21.0.1)

Collecting pip

  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)

     |████████████████████████████████| 1.7 MB 4.7 MB/s 

Installing collected packages: pip

  Attempting uninstall: pip

    Found existing installation: pip 21.0.1

    Uninstalling pip-21.0.1:

      Successfully uninstalled pip-21.0.1

Successfully installed pip-21.3.1


0 件のコメント :

コメントを投稿