macでjupyterを利用するまでのメモ
Jupyter Notebookを利用する機会がでてきたのでセットアップしたときのメモです。
ターミナルがfishなのでfishユーザー向け。
これまでpythonについてはノータッチなのですべてデフォのままです。
mac環境
Distro: OS X 10.14.2
現状のpythonのバージョンと場所の確認
$ python --version
Python 2.7.10
$ which python
/usr/bin/python
anyenvを利用してpyenvをインストール
brewを利用してインストールでもいいのですが、以前nbenvをインストールする時にanyenvを利用したので今回もanyenvを利用します。
anyenvのインストールについてはこちらを参考にどうぞ(これもターミナルはfishです。)
fishターミナルでanyenvとndenvをインストールする。
$ anyenv install pyenv
/var/folders/nw/v6df8bkj4y9b0qf8h4tzlv1w0000gp/T/pyenv.20190110233027.71677 ~/current_dir
Cloning https://github.com/yyuu/pyenv.git...
Cloning into 'pyenv'...
remote: Enumerating objects: 34, done.
remote: Counting objects: 100% (34/34), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 16594 (delta 10), reused 24 (delta 8), pack-reused 16560
Receiving objects: 100% (16594/16594), 3.21 MiB | 757.00 KiB/s, done.
Resolving deltas: 100% (11244/11244), done.
~/current_dir
Install pyenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session.
インストールすることができました。
どこにインストールされたのかはanyenv versions
コマンドを叩くと確認することができます。
ターミナルのfishでは$
を実行することができません。
のでPlease reload your profile (exec $SHELL -l) or open a new session.
をする代わりに環境変数の設定をconfig.fish
に設定します。
$ vi ~/.config/fish/config.fish
viを起動して以下の設定を追加します。
set -x PYENV_ROOT $HOME/.anyenv/envs/pyenv
set -x PATH $HOME/.anyenv/envs/pyenv/bin $PATH
pyenv init - | source
設定したあとは source ~/.config/fish/config.fish
を実行します。
$ pyenv
pyenv 1.2.9
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
local Set or show the local application-specific Python version
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install a Python version using python-build
uninstall Uninstall a specific Python version
rehash Rehash pyenv shims (run this after installing executables)
version Show the current Python version and its origin
versions List all Python versions available to pyenv
which Display the full path to an executable
whence List all Python versions that contain the given executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
pyenvのコマンド一覧が表示されればOKです。
pythonのバージョンをインストールする
pyenvを利用してpython3.5をインストールします。
$ pyenv install 3.5.0
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.5.0.tar.xz...
-> https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz
Installing Python-3.5.0...
python-build: use readline from homebrew
Installed Python-3.5.0 to /Users/gulliver/.anyenv/envs/pyenv/versions/3.5.0
pyenv versions
コマンドを叩いて3.5.0
が表示されていればOKです。
jupyterを動かすためのフォルダ用意する
pythonのバージョンを指定したフォルダを作成します。
$ mkdir works; and cd works
$ python local 3.5.0
$ python --version
Python 3.5.0
jupyterをインストール
$ python3 -m pip install --upgrade pip
$ python3 -m pip install jupyter
公式のコマンドをそのまま叩きました。 こちら
jupyterを起動する
$ jupyter notebook
[I 00:11:49.243 NotebookApp] Serving notebooks from local directory: /current_dir/jupyter-notebook
[I 00:11:49.243 NotebookApp] The Jupyter Notebook is running at:
[I 00:11:49.243 NotebookApp] http://localhost:8888/?token=f6e107dbda7a3505fe0ba2e5b827d716ef6fbde620b3e1bc
[I 00:11:49.243 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
jupyter notebookが起動しました。