-macOS- PythonとJupyter Notebookのインストール

以前は,Anacondaをインストールして,PythonとJupyter Notebookを使用していたのですが,Anacondaは重たく,パッケージのアップデートが上手くいかないので,インストール方法を変更してみました.
インストールは全て,ターミナルから行います.

Command Line ToolとHomebrewがインストールされている前提です.

まずは,Pythonをインストールします.macOSにはデフォルトでPython 2.7がインストールされていますが,Python 3でコーディングを行いたいので,Python 3をインストールします.

ターミナルから以下のコマンドを実行します.

$ brew install python3
 
インストールが完了したら,Python3を起動してみて,インストールが成功しているかどうかを確認します.
$ python3
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
 
Python3がインストールされると,pip3も同時にインストールされます.一応,pip3がインストールされているかを確認してみます.
$ pip3 -v
すると,以下のように表示されます.
Usage:   
  pip3 <command> [options]
 
Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.
 
General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring
                              environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be
                              used up to 3 times (corresponding to WARNING,
                              ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
  --trusted-host <hostname>   Mark this host as trusted, even though it does
                              not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output
MBP:~ hide$ pip3 install --upgrade setuptools
Collecting setuptools
    100% |████████████████████████████████| 583kB 5.9MB/s 
Installing collected packages: setuptools
  Found existing installation: setuptools 40.8.0
    Uninstalling setuptools-40.8.0:
      Successfully uninstalled setuptools-40.8.0
Successfully installed setuptools-41.0.0
 
pip3を使って,NumPy*,SciPy**,Scikit-Learn***,MatPlotLib*4,Pillow*5,PyMc3*6パッケージをインストールします.
$ pip3 install numpy
 
$ pip3 install scipy
 
$ pip3 install scikit-learn
 
$ pip3 install matplotlib
 
$ pip3 install Pillow
 
$ pip3 install PyMC
 
他のパッケージをインストールしたい場合は
$ pip3 install Package Name
としてインストールします.
 
続いて,Jupyter Notebook*7をインストールします.
$ pip3 install jupyter
 
インストールが完了したら,Jupyter Notebookを起動します.
$ jupyter notebook
 
これで,ブラウザが開いてJupyter Notebookが起動すれば成功です.
-----
* NumPy インストール時の表示
Collecting numpy
    100% |████████████████████████████████| 13.9MB 1.9MB/s 
Installing collected packages: numpy
Successfully installed numpy-1.16.3
 
** SciPy インストール時の表示
Collecting scipy
    100% |████████████████████████████████| 27.3MB 1.2MB/s 
Requirement already satisfied: numpy>=1.8.2 in /usr/local/lib/python3.7/site-packages (from scipy) (1.16.3)
Installing collected packages: scipy
inSuccessfully installed scipy-1.2.1
 
*** Scikit-Learn インストール時の表示
Collecting scikit-learn
    100% |████████████████████████████████| 8.0MB 2.5MB/s 
Requirement already satisfied: scipy>=0.13.3 in /usr/local/lib/python3.7/site-packages (from scikit-learn) (1.2.1)
Requirement already satisfied: numpy>=1.8.2 in /usr/local/lib/python3.7/site-packages (from scikit-learn) (1.16.3)
Installing collected packages: scikit-learn
Successfully installed scikit-learn-0.20.3
 
*4 MatPlotLib インストール時の表示
Collecting matplotlib
    100% |████████████████████████████████| 14.3MB 1.5MB/s 
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
    100% |████████████████████████████████| 71kB 9.2MB/s 
Collecting cycler>=0.10 (from matplotlib)
Collecting python-dateutil>=2.1 (from matplotlib)
    100% |████████████████████████████████| 235kB 5.0MB/s 
Collecting kiwisolver>=1.0.1 (from matplotlib)
    100% |████████████████████████████████| 112kB 4.0MB/s 
Requirement already satisfied: numpy>=1.10.0 in /usr/local/lib/python3.7/site-packages (from matplotlib) (1.16.3)
Collecting six (from cycler>=0.10->matplotlib)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib) (41.0.0)
Installing collected packages: pyparsing, six, cycler, python-dateutil, kiwisolver, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-3.0.3 pyparsing-2.4.0 python-dateutil-2.8.0 six-1.12.0


*5 Pillow インストール時の表示

Collecting Pillow
    100% |████████████████████████████████| 3.7MB 1.9MB/s 
Installing collected packages: Pillow
Successfully installed Pillow-6.0.0
MBP:~ hide$ pip3 install pandas
Collecting pandas
    100% |████████████████████████████████| 15.9MB 1.2MB/s 
Collecting pytz>=2011k (from pandas)
    100% |████████████████████████████████| 512kB 4.6MB/s 
Requirement already satisfied: numpy>=1.12.0 in /usr/local/lib/python3.7/site-packages (from pandas) (1.16.3)
Requirement already satisfied: python-dateutil>=2.5.0 in /usr/local/lib/python3.7/site-packages (from pandas) (2.8.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)
Installing collected packages: pytz, pandas
Successfully installed pandas-0.24.2 pytz-2019.1
 
*6 PyMc3 インストール時の表示
Collecting PyMc3
    100% |████████████████████████████████| 30.7MB 1.1MB/s 
Collecting theano>=1.0.0 (from PyMc3)
    100% |████████████████████████████████| 2.8MB 2.0MB/s 
Requirement already satisfied: numpy>=1.13.0 in /usr/local/lib/python3.7/site-packages (from PyMc3) (1.16.3)
Requirement already satisfied: scipy>=0.18.1 in /usr/local/lib/python3.7/site-packages (from PyMc3) (1.2.1)
Requirement already satisfied: pandas>=0.18.0 in /usr/local/lib/python3.7/site-packages (from PyMc3) (0.24.2)
Collecting patsy>=0.4.0 (from PyMc3)
    100% |████████████████████████████████| 235kB 4.1MB/s 
Collecting joblib<0.13.0 (from PyMc3)
    100% |████████████████████████████████| 276kB 626kB/s 
Collecting tqdm>=4.8.4 (from PyMc3)
    100% |████████████████████████████████| 51kB 13.4MB/s 
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.7/site-packages (from PyMc3) (1.12.0)
Collecting h5py>=2.7.0 (from PyMc3)
    100% |████████████████████████████████| 6.2MB 2.5MB/s 
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.7/site-packages (from pandas>=0.18.0->PyMc3) (2019.1)
Requirement already satisfied: python-dateutil>=2.5.0 in /usr/local/lib/python3.7/site-packages (from pandas>=0.18.0->PyMc3) (2.8.0)
Building wheels for collected packages: PyMc3, theano
  Building wheel for PyMc3 (setup.py) ... done
  Stored in directory: /Users/hide/Library/Caches/pip/wheels/f1/08/5d/2cee5bff1159b3b4754377f51b0e4f40f116e8d4e069acbcdc
  Building wheel for theano (setup.py) ... done
  Stored in directory: /Users/hide/Library/Caches/pip/wheels/88/fb/be/483910ff7e9f703f30a10605ad7605f3316493875c86637014
Successfully built PyMc3 theano
Installing collected packages: theano, patsy, joblib, tqdm, h5py, PyMc3
Successfully installed PyMc3-3.6 h5py-2.9.0 joblib-0.12.5 patsy-0.5.1 theano-1.0.4 tqdm-4.31.1
 
*7 Jupyter Notebookインストール時の表示
Collecting jupyter
Collecting jupyter-console (from jupyter)
Collecting nbconvert (from jupyter)
    100% |████████████████████████████████| 409kB 4.8MB/s 
Collecting ipywidgets (from jupyter)
    100% |████████████████████████████████| 112kB 597kB/s 
Collecting ipykernel (from jupyter)
    100% |████████████████████████████████| 122kB 775kB/s 
Collecting qtconsole (from jupyter)
    100% |████████████████████████████████| 122kB 751kB/s 
Collecting notebook (from jupyter)
    100% |████████████████████████████████| 9.0MB 2.6MB/s 
Collecting jupyter-client (from jupyter-console->jupyter)
    100% |████████████████████████████████| 92kB 2.3MB/s 
Collecting ipython (from jupyter-console->jupyter)
    100% |████████████████████████████████| 778kB 5.0MB/s 
Collecting pygments (from jupyter-console->jupyter)
    100% |████████████████████████████████| 849kB 2.9MB/s 
Collecting prompt-toolkit<2.1.0,>=2.0.0 (from jupyter-console->jupyter)
    100% |████████████████████████████████| 337kB 2.1MB/s 
Collecting pandocfilters>=1.4.1 (from nbconvert->jupyter)
Collecting entrypoints>=0.2.2 (from nbconvert->jupyter)
Collecting jupyter-core (from nbconvert->jupyter)
    100% |████████████████████████████████| 133kB 2.7MB/s 
Collecting mistune>=0.8.1 (from nbconvert->jupyter)
Collecting traitlets>=4.2 (from nbconvert->jupyter)
    100% |████████████████████████████████| 81kB 4.0MB/s 
Collecting bleach (from nbconvert->jupyter)
    100% |████████████████████████████████| 163kB 3.5MB/s 
Collecting defusedxml (from nbconvert->jupyter)
Collecting testpath (from nbconvert->jupyter)
    100% |████████████████████████████████| 163kB 3.8MB/s 
Collecting jinja2 (from nbconvert->jupyter)
    100% |████████████████████████████████| 133kB 1.2MB/s 
Collecting nbformat>=4.4 (from nbconvert->jupyter)
    100% |████████████████████████████████| 163kB 2.5MB/s 
Collecting widgetsnbextension~=3.4.0 (from ipywidgets->jupyter)
    100% |████████████████████████████████| 2.2MB 888kB/s 
Collecting tornado>=4.2 (from ipykernel->jupyter)
    100% |████████████████████████████████| 491kB 380kB/s 
Collecting ipython-genutils (from qtconsole->jupyter)
Collecting pyzmq>=17 (from notebook->jupyter)
    100% |████████████████████████████████| 819kB 400kB/s 
Collecting prometheus-client (from notebook->jupyter)
Collecting terminado>=0.8.1 (from notebook->jupyter)
Collecting Send2Trash (from notebook->jupyter)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/site-packages (from jupyter-client->jupyter-console->jupyter) (2.8.0)
Collecting backcall (from ipython->jupyter-console->jupyter)
Collecting jedi>=0.10 (from ipython->jupyter-console->jupyter)
    100% |████████████████████████████████| 184kB 817kB/s 
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.7/site-packages (from ipython->jupyter-console->jupyter) (41.0.0)
Collecting appnope; sys_platform == "darwin" (from ipython->jupyter-console->jupyter)
Collecting pexpect; sys_platform != "win32" (from ipython->jupyter-console->jupyter)
    100% |████████████████████████████████| 61kB 2.2MB/s 
Collecting pickleshare (from ipython->jupyter-console->jupyter)
Collecting decorator (from ipython->jupyter-console->jupyter)
Collecting wcwidth (from prompt-toolkit<2.1.0,>=2.0.0->jupyter-console->jupyter)
Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.7/site-packages (from prompt-toolkit<2.1.0,>=2.0.0->jupyter-console->jupyter) (1.12.0)
Collecting webencodings (from bleach->nbconvert->jupyter)
Collecting MarkupSafe>=0.23 (from jinja2->nbconvert->jupyter)
Collecting jsonschema!=2.5.0,>=2.4 (from nbformat>=4.4->nbconvert->jupyter)
    100% |████████████████████████████████| 61kB 3.1MB/s 
Collecting ptyprocess; os_name != "nt" (from terminado>=0.8.1->notebook->jupyter)
Collecting parso>=0.3.0 (from jedi>=0.10->ipython->jupyter-console->jupyter)
    100% |████████████████████████████████| 102kB 2.7MB/s 
Collecting pyrsistent>=0.14.0 (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4->nbconvert->jupyter)
    100% |████████████████████████████████| 112kB 3.3MB/s 
Collecting attrs>=17.4.0 (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4->nbconvert->jupyter)
Building wheels for collected packages: pandocfilters, tornado, prometheus-client, backcall, pyrsistent
  Building wheel for pandocfilters (setup.py) ... done
  Stored in directory: /Users/hide/Library/Caches/pip/wheels/39/01/56/f1b08a6275acc59e846fa4c1e1b65dbc1919f20157d9e66c20
  Building wheel for tornado (setup.py) ... done
  Stored in directory: /Users/hide/Library/Caches/pip/wheels/61/7e/7a/5e02e60dc329aef32ecf70e0425319ee7e2198c3a7cf98b4a2
  Building wheel for prometheus-client (setup.py) ... done
  Stored in directory: /Users/hide/Library/Caches/pip/wheels/4b/04/b8/3709c73e7453f311ebd46ad581b89642543213f995e2659b9e
  Building wheel for backcall (setup.py) ... done
  Stored in directory: /Users/hide/Library/Caches/pip/wheels/98/b0/dd/29e28ff615af3dda4c67cab719dd51357597eabff926976b45
  Building wheel for pyrsistent (setup.py) ... done
  Stored in directory: /Users/hide/Library/Caches/pip/wheels/83/59/9a/a037b9b3c3e93d9275ea0aff9d6064400f372879dfdab01afe
Successfully built pandocfilters tornado prometheus-client backcall pyrsistent
Installing collected packages: ipython-genutils, decorator, traitlets, tornado, jupyter-core, pyzmq, jupyter-client, backcall, parso, jedi, appnope, pygments, ptyprocess, pexpect, pickleshare, wcwidth, prompt-toolkit, ipython, ipykernel, jupyter-console, pandocfilters, entrypoints, mistune, webencodings, bleach, defusedxml, testpath, MarkupSafe, jinja2, pyrsistent, attrs, jsonschema, nbformat, nbconvert, prometheus-client, terminado, Send2Trash, notebook, widgetsnbextension, ipywidgets, qtconsole, jupyter
Successfully installed MarkupSafe-1.1.1 Send2Trash-1.5.0 appnope-0.1.0 attrs-19.1.0 backcall-0.1.0 bleach-3.1.0 decorator-4.4.0 defusedxml-0.6.0 entrypoints-0.3 ipykernel-5.1.0 ipython-7.4.0 ipython-genutils-0.2.0 ipywidgets-7.4.2 jedi-0.13.3 jinja2-2.10.1 jsonschema-3.0.1 jupyter-1.0.0 jupyter-client-5.2.4 jupyter-console-6.0.0 jupyter-core-4.4.0 mistune-0.8.4 nbconvert-5.4.1 nbformat-4.4.0 notebook-5.7.8 pandocfilters-1.4.2 parso-0.4.0 pexpect-4.7.0 pickleshare-0.7.5 prometheus-client-0.6.0 prompt-toolkit-2.0.9 ptyprocess-0.6.0 pygments-2.3.1 pyrsistent-0.14.11 pyzmq-18.0.1 qtconsole-4.4.3 terminado-0.8.2 testpath-0.4.2 tornado-6.0.2 traitlets-4.3.2 wcwidth-0.1.7 webencodings-0.5.1 widgetsnbextension-3.4.2