LoginSignup
8
7

More than 5 years have passed since last update.

最近pythonを使って色々なプログラムを書いているのですが、pythonを簡単に実行できるJupyterなるツールがあると聞いたので今回はJupyterについて書いていきたいと思います。

動作環境

  • Mac OS High Sierra 10.13.2
  • pyenv 1.1.5
  • pip 9.0.1
  • python 3.6.3

前提条件

  • pyenv
  • pip
  • python3系

上記をインストール済みであること。
これらのインストールがまだの方はこちらの記事をご参考ください。
pythonの環境を再構築!!【開発環境の構築編】

Jupyterをインストール

まずは作業をするためのディレクトリと新しい仮想環境を用意します。

bash
$ mkdir jupyter-notebooks

$ cd jupyter-notebooks/

$ pyenv virtualenv 3.6.3 jupy
Requirement already satisfied: setuptools in /Users/user/.pyenv/versions/3.6.3/envs/jupy/lib/python3.6/site-packages
Requirement already satisfied: pip in /Users/user/.pyenv/versions/3.6.3/envs/jupy/lib/python3.6/site-packages

$ pyenv local jupy

(jupy)$

とりあえずこれでJupyterのインストールを開始する準備はできました。では!早速やっていきましょう!

bash
(jupy)$ pip install jupyter
Collecting jupyter
  Downloading jupyter-1.0.0-py2.py3-none-any.whl
Collecting ipywidgets (from jupyter)
  Downloading ipywidgets-7.0.5-py2.py3-none-any.whl (68kB)
    100% |████████████████████████████████| 71kB 1.7MB/s
Collecting qtconsole (from jupyter)
  Downloading qtconsole-4.3.1-py2.py3-none-any.whl (108kB)
    100% |████████████████████████████████| 112kB 2.0MB/s
Collecting notebook (from jupyter)
  Downloading notebook-5.2.2-py2.py3-none-any.whl (8.0MB)
    100% |████████████████████████████████| 8.0MB 186kB/s

...省略...

  Downloading py-1.5.2-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 3.9MB/s
Collecting pluggy<0.7,>=0.5 (from pytest; python_version >= "3.4" or python_version == "2.7" and extra == "test"->jupyter-client>=4.1->qtconsole->jupyter)
  Downloading pluggy-0.6.0.tar.gz
Collecting attrs>=17.2.0 (from pytest; python_version >= "3.4" or python_version == "2.7" and extra == "test"->jupyter-client>=4.1->qtconsole->jupyter)
  Downloading attrs-17.3.0-py2.py3-none-any.whl
Collecting webencodings (from html5lib!=1.0b1,!=1.0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999999pre->bleach->nbconvert->jupyter)
  Downloading webencodings-0.5.1-py2.py3-none-any.whl
Installing collected packages: six, decorator, ipython-genutils, traitlets, pyzmq, python-dateutil, py, pluggy, attrs, pytest, jupyter-core, jupyter-client, tornado, ptyprocess, pexpect, pickleshare, simplegeneric, pygments, parso, jedi, wcwidth, prompt-toolkit, appnope, ipython, ipykernel, jsonschema, nbformat, MarkupSafe, jinja2, pandocfilters, entrypoints, webencodings, html5lib, bleach, mistune, testpath, nbconvert, terminado, notebook, widgetsnbextension, ipywidgets, qtconsole, jupyter-console, jupyter
  Running setup.py install for pluggy ... done
  Running setup.py install for tornado ... done
  Running setup.py install for simplegeneric ... done
  Running setup.py install for MarkupSafe ... done
  Running setup.py install for pandocfilters ... done
Successfully installed MarkupSafe-1.0 appnope-0.1.0 attrs-17.3.0 bleach-2.1.2 decorator-4.1.2 entrypoints-0.2.3 html5lib-1.0.1 ipykernel-4.7.0 ipython-6.2.1 ipython-genutils-0.2.0 ipywidgets-7.0.5 jedi-0.11.1 jinja2-2.10 jsonschema-2.6.0 jupyter-1.0.0 jupyter-client-5.2.0 jupyter-console-5.2.0 jupyter-core-4.4.0 mistune-0.8.3 nbconvert-5.3.1 nbformat-4.4.0 notebook-5.2.2 pandocfilters-1.4.2 parso-0.1.1 pexpect-4.3.1 pickleshare-0.7.4 pluggy-0.6.0 prompt-toolkit-1.0.15 ptyprocess-0.5.2 py-1.5.2 pygments-2.2.0 pytest-3.3.1 python-dateutil-2.6.1 pyzmq-16.0.3 qtconsole-4.3.1 simplegeneric-0.8.1 six-1.11.0 terminado-0.8.1 testpath-0.3.1 tornado-4.5.2 traitlets-4.3.2 wcwidth-0.1.7 webencodings-0.5.1 widgetsnbextension-3.0.8

うん...実行結果については結構長かったので省略しています。とりあえずエラーが出ることなく一番下の行Successfully installedが出れば大丈夫だと思います!

Jupyterの使用方法

それでは早速Jupyterを起動してみます。

bash
(jupy)$ jupyter notebook

するとこのようにブラウザが起動します。

wake-up-jupyter.png

右上にLogoutがありますが、そのちょっとしたの方のNewを押すとこのようにPython3というのが出てくるのでこれをクリックします。

jupyter-newfile.png

このような画面が出たら準備は完了です!早速Pythonを書いていきましょう!!!

python3-login.png

まずは手始めにhello world!を出力してみます。
In[]:print(hello world!)と入力したらそのすぐ上にあるRunを押すかshift + enterで実行することができます。

hello.png

最高ですね!!
これなら手軽にpythonでプログラムが書けそうです!

ちょっとした雑談

今回はpythonで開発するときに使えるJupyterというツールについて書かしていただきました。インストールも簡単ですし、コードの実行も手軽にできるのでぜひ一度使って見ることをお勧めします!

参考にした記事・本

【Python】pyenv+virtualenv+JupyterのPython環境の構築
池内孝啓・片柳薫子・岩尾エマはるか・@driller「PythonユーザのためのJupyter[実践]入門」(2017)

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7