Opensourcetechブログ

OpensourcetechによるLinux・オープンソース・IT技術などに関するブログです。

nginx mainline 1.15.2 リリース!!

 

 

こんにちは、オープンソース技研鯨井貴博です。

 

nginx mainline の新バージョン、1.15.2がリリースされました。

f:id:opensourcetech:20180725153539p:plain

nginx news

 

 

更新内容は、以下の通り。

https://nginx.org/en/CHANGES

-------

Changes with nginx 1.15.2 24 Jul 2018

*) Feature: the $ssl_preread_protocol variable in the ngx_stream_ssl_preread_module.

*) Feature: now when using the "reset_timedout_connection" directive nginx will reset connections being closed with the 444 code.

*) Change: a logging level of the "http request", "https proxy request", "unsupported protocol", and "version too low" SSL errors has been lowered from "crit" to "info".

*) Bugfix: DNS requests were not resent if initial sending of a request failed.

*) Bugfix: the "reuseport" parameter of the "listen" directive was ignored if the number of worker processes was specified after the "listen" directive.

*) Bugfix: when using OpenSSL 1.1.0 or newer it was not possible to switch off "ssl_prefer_server_ciphers" in a virtual server if it was switched on in the default server.

*) Bugfix: SSL session reuse with upstream servers did not work with the TLS 1.3 protocol.

 

Updates(日本語訳)

-------

*)機能追加:ngx_stream_ssl_preread_module の 変数$ssl_preread_protocol を追加

*)機能追加: "reset_timedout_connection"ディレクティブを使用すると、nginxはコネクションを444コードでリセットする

*)変更:「http request」、「https proxy request」、「unsupported protocol」、「ersion too low」のSSLエラーに関するロギングレベルが「crit」から「info」に変更

*)バグ修正:リクエストの初期送信が失敗した場合、DNSリクエストは再送信されない

*)バグ修正: "listen"ディレクティブの後にワーカープロセスの数が指定された場合、 "listen"ディレクティブの "reuseport"パラメータは無視される

*)バグ修正:OpenSSL 1.1.0以降を使用しているおり、仮想サーバーがデフォルトサーバーでオンになっている場合、「ssl_prefer_server_ciphers」をオフに出来なかった

*)バグ修正:TLS 1.3プロトコルでは、アップストリームサーバーとのSSLセッションの再利用が機能しなかった

 

 

nginx mainline使用されている方は、ぜひ最新版へのアップデートを!!

 

 

 

オープンソース技研

www.slideshare.net

github.com

www.facebook.com

twitter.com

www.instagram.com

 

 

にほんブログ村 IT技術ブログ Linuxへ
Linux

にほんブログ村 IT技術ブログ オープンソースへ
オープンソース

 

bitFlyer ビットコインを始めるなら安心・安全な取引所で

ビットコイン取引高日本一の仮想通貨取引所 coincheck bitcoin

 

 

AIを学ぶ5 〜TensorFlow & Keras を使ってみる〜

 

 

こんにちは、オープンソース技研鯨井貴博です。

 

今回は、AI(深層学習や機械学習)に利用できる Pythonのライブラリ、

TensorFlow と Kerasを使ってみます。

 

 

TensorFlow とは?

Google が開発し公開している 機械学習の為のライブラリです。

TensorFlow

 ※テンサーフロー、テンソルフロー 両方で世の中では呼ばれているようですが、

 リンクをみると後者が正しい模様。

 

オープンソースなので、ソースコードGithubで公開されています。

github.com

 

Keras とは?

Pythonで書かれたTensorFlow(そのほか、CNTK・Theanoなど)で実行可能な、高水準のニューラルネットワークライブラリです。

https://keras.io/ja/

 

こちらもオープンソースなので、Githubでコードが公開されています。

github.com

 

 

pip3 を使用してインストール

pip3 から各ライブラリをインストールします。

なお、pip3が入っていない場合、以下を参照ください。

opensourcetech.hatenablog.jp

HayashiyaKikuzo:~ xxx$ pip3 install --upgrade tensorflow・・・・TensorFlowのインストール
Collecting tensorflow
Using cached https://files.pythonhosted.org/packages/57/38/96ee343729363297d62311272adc28b466d30f74c87dc645badb0102af56/tensorflow-1.9.0-cp36-cp36m-macosx_10_11_x86_64.whl
Requirement not upgraded as not directly required: tensorboard<1.10.0,>=1.9.0 in /usr/local/lib/python3.6/site-packages (from tensorflow) (1.9.0)
Requirement not upgraded as not directly required: grpcio>=1.8.6 in /usr/local/lib/python3.6/site-packages (from tensorflow) (1.13.0)
Requirement not upgraded as not directly required: termcolor>=1.1.0 in /usr/local/lib/python3.6/site-packages (from tensorflow) (1.1.0)
Requirement not upgraded as not directly required: wheel>=0.26 in /usr/local/lib/python3.6/site-packages (from tensorflow) (0.31.0)
Requirement not upgraded as not directly required: gast>=0.2.0 in /usr/local/lib/python3.6/site-packages (from tensorflow) (0.2.0)
Requirement not upgraded as not directly required: setuptools<=39.1.0 in /usr/local/lib/python3.6/site-packages (from tensorflow) (39.0.1)
Requirement not upgraded as not directly required: six>=1.10.0 in /usr/local/lib/python3.6/site-packages (from tensorflow) (1.11.0)
Requirement not upgraded as not directly required: numpy>=1.13.3 in /usr/local/lib/python3.6/site-packages (from tensorflow) (1.14.5)
Requirement not upgraded as not directly required: astor>=0.6.0 in /usr/local/lib/python3.6/site-packages (from tensorflow) (0.7.1)
Requirement not upgraded as not directly required: protobuf>=3.4.0 in /usr/local/lib/python3.6/site-packages (from tensorflow) (3.6.0)
Requirement not upgraded as not directly required: absl-py>=0.1.6 in /usr/local/lib/python3.6/site-packages (from tensorflow) (0.2.2)
Requirement not upgraded as not directly required: markdown>=2.6.8 in /usr/local/lib/python3.6/site-packages (from tensorboard<1.10.0,>=1.9.0->tensorflow) (2.6.11)
Requirement not upgraded as not directly required: werkzeug>=0.11.10 in /usr/local/lib/python3.6/site-packages (from tensorboard<1.10.0,>=1.9.0->tensorflow) (0.14.1)
Installing collected packages: tensorflow
Successfully installed tensorflow-1.9.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

HayashiyaKikuzo:~ xxx$ pip3 install keras・・・・Kerasのインストール
Collecting keras
Downloading https://files.pythonhosted.org/packages/68/12/4cabc5c01451eb3b413d19ea151f36e33026fc0efb932bf51bcaf54acbf5/Keras-2.2.0-py2.py3-none-any.whl (300kB)
100% |████████████████████████████████| 307kB 5.0MB/s
Collecting keras-applications==1.0.2 (from keras)
Downloading https://files.pythonhosted.org/packages/e2/60/c557075e586e968d7a9c314aa38c236b37cb3ee6b37e8d57152b1a5e0b47/Keras_Applications-1.0.2-py2.py3-none-any.whl (43kB)
100% |████████████████████████████████| 51kB 9.8MB/s
Collecting keras-preprocessing==1.0.1 (from keras)
Downloading https://files.pythonhosted.org/packages/f8/33/275506afe1d96b221f66f95adba94d1b73f6b6087cfb6132a5655b6fe338/Keras_Preprocessing-1.0.1-py2.py3-none-any.whl
Collecting scipy>=0.14 (from keras)
Downloading https://files.pythonhosted.org/packages/a0/b6/70bf61c1badb5fea82d4c558e05e76c2dee5e77bb072fe465d7c7a87287d/scipy-1.1.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (16.7MB)
100% |████████████████████████████████| 16.7MB 2.0MB/s
Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.6/site-packages (from keras) (1.14.5)
Collecting h5py (from keras)
Downloading https://files.pythonhosted.org/packages/44/81/50a0560aac57a33c2a624d9e160735f39d7a6324e3f6f115425a1bf01dd9/h5py-2.8.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (6.0MB)
100% |████████████████████████████████| 6.1MB 5.8MB/s
Collecting pyyaml (from keras)
Downloading https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz (270kB)
100% |████████████████████████████████| 276kB 20.2MB/s
Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.6/site-packages (from keras) (1.11.0)
Building wheels for collected packages: pyyaml
Running setup.py bdist_wheel for pyyaml ... done
Stored in directory: /Users/xxx/Library/Caches/pip/wheels/ad/da/0c/74eb680767247273e2cf2723482cb9c924fe70af57c334513f
Successfully built pyyaml
Installing collected packages: h5py, keras-applications, scipy, keras-preprocessing, pyyaml, keras
Successfully installed h5py-2.8.0 keras-2.2.0 keras-applications-1.0.2 keras-preprocessing-1.0.1 pyyaml-3.13 scipy-1.1.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

HayashiyaKikuzo:~ xxx$ pip3 list
Package Version
------------------- -------
absl-py 0.2.2
appnope 0.1.0
astor 0.7.1
backcall 0.1.0
bleach 2.1.3
cycler 0.10.0
decorator 4.3.0
entrypoints 0.2.3
gast 0.2.0
grpcio 1.13.0
h5py 2.8.0
html5lib 1.0.1
ipykernel 4.8.2
ipython 6.4.0
ipython-genutils 0.2.0
ipywidgets 7.3.0
jedi 0.12.1
Jinja2 2.10
jsonschema 2.6.0
jupyter 1.0.0
jupyter-client 5.2.3
jupyter-console 5.2.0
jupyter-core 4.4.0
Keras 2.2.0    <----------------Keras、入りました!
Keras-Applications 1.0.2
Keras-Preprocessing 1.0.1
kiwisolver 1.0.1
Markdown 2.6.11
MarkupSafe 1.0
matplotlib 2.2.2
mistune 0.8.3
nbconvert 5.3.1
nbformat 4.4.0
neo4j-driver 1.5.3
notebook 5.6.0
numpy 1.14.5
pandocfilters 1.4.2
parso 0.3.1
pexpect 4.6.0
pickleshare 0.7.4
pip 10.0.1
prometheus-client 0.3.0
prompt-toolkit 1.0.15
protobuf 3.6.0
ptyprocess 0.6.0
Pygments 2.2.0
pyparsing 2.2.0
python-dateutil 2.7.3
pytz 2018.5
PyYAML 3.13
pyzmq 17.1.0
qtconsole 4.3.1
scipy 1.1.0
Send2Trash 1.5.0
setuptools 39.0.1
simplegeneric 0.8.1
six 1.11.0
tensorboard 1.9.0
tensorflow 1.9.0    <----------------TensorFlow、入りました!
termcolor 1.1.0
terminado 0.8.1
testpath 0.3.1
tornado 5.1
traitlets 4.3.2
wcwidth 0.1.7
webencodings 0.5.1
Werkzeug 0.14.1
wheel 0.31.0
widgetsnbextension 3.3.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

 

 

 TensorFlow を試してみる

Install TensorFlow on macOS  |  TensorFlow

f:id:opensourcetech:20180723162517p:plain

上記リンク内にあるサンプルを使って、TensorFlow を試してみます。

HayashiyaKikuzo:~ xxx$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
/Users/xxx/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2018-07-22 15:38:00.014977: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
>>> print(sess.run(hello))
b'Hello, TensorFlow!'   <--------何故だろう、先頭に「b」がつく!?
>>> print(sess.run(hello).decode())   <-------先頭に「b」がつく問題対応
Hello, TensorFlow!
>>> exit()

 

上記、先頭に「b」がつく問題ですが、

StackOverFlow から対応策がわかりました。

stackoverflow.com

 

 

 TensorFlow & Keras を試してみる

こちらは、以下のチュートリアルにあるサンプルを使って試してみます。

www.tensorflow.orgf:id:opensourcetech:20180723163028p:plain

HayashiyaKikuzo:~ xxx$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
/Users/xxx/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
>>> mnist = tf.keras.datasets.mnist
>>> (x_train, y_train),(x_test, y_test) = mnist.load_data()
Downloading data from https://s3.amazonaws.com/img-datasets/mnist.npz
11493376/11490434 [==============================] - 4s 0us/step
>>> x_train, x_test = x_train / 255.0, x_test / 255.0
>>> model = tf.keras.models.Sequential([
... tf.keras.layers.Flatten(),
... tf.keras.layers.Dense(512, activation=tf.nn.relu),
... tf.keras.layers.Dropout(0.2),
... tf.keras.layers.Dense(10, activation=tf.nn.softmax)
... ])
>>> model.compile(optimizer='adam',
... loss='sparse_categorical_crossentropy',
... metrics=['accuracy'])
>>> model.fit(x_train, y_train, epochs=5)
Epoch 1/5
2018-07-22 15:47:52.769419: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
60000/60000 [==============================] - 15s 249us/step - loss: 0.2201 - acc: 0.9349
Epoch 2/5
60000/60000 [==============================] - 14s 237us/step - loss: 0.0971 - acc: 0.9710
Epoch 3/5
60000/60000 [==============================] - 14s 238us/step - loss: 0.0681 - acc: 0.9786
Epoch 4/5
60000/60000 [==============================] - 14s 236us/step - loss: 0.0536 - acc: 0.9825
Epoch 5/5
60000/60000 [==============================] - 14s 235us/step - loss: 0.0435 - acc: 0.9858
<tensorflow.python.keras.callbacks.History object at 0xb1feab5f8>
>>> model.evaluate(x_test, y_test)
10000/10000 [==============================] - 0s 43us/step
[0.06850039585522026, 0.9803]
>>> exit()

 

 

  TensorFlow インストールに関するトラブルシュート

TensorFlow のインストールを、当初「pip3 install tensorflow」で行ったのですが

モジュールの読み込みの際、以下のようなエラーが出力されました。

HayashiyaKikuzo:~ xxx$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'  <--- 出力されたエラーメッセージ
>>> exit()

 

以下、解決策。(TensorFlowを --upgradeオプションをつけて再インストール)

HayashiyaKikuzo:~ xxx$ pip3 uninstall tensorflow・・・・一旦、アンインストール
Uninstalling tensorflow-1.9.0:
Would remove:
/usr/local/bin/freeze_graph
/usr/local/bin/saved_model_cli
/usr/local/bin/tensorboard
/usr/local/bin/tflite_convert
/usr/local/bin/toco
/usr/local/bin/toco_from_protos
/usr/local/lib/python3.6/site-packages/tensorflow-1.9.0.dist-info/*
/usr/local/lib/python3.6/site-packages/tensorflow/*
Proceed (y/n)? y
Successfully uninstalled tensorflow-1.9.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
HayashiyaKikuzo:~ xxx$ pip3 list
Package Version
------------------- -------
absl-py 0.2.2
appnope 0.1.0
astor 0.7.1
backcall 0.1.0
bleach 2.1.3
cycler 0.10.0
decorator 4.3.0
entrypoints 0.2.3
gast 0.2.0
grpcio 1.13.0
h5py 2.8.0
html5lib 1.0.1
ipykernel 4.8.2
ipython 6.4.0
ipython-genutils 0.2.0
ipywidgets 7.3.0
jedi 0.12.1
Jinja2 2.10
jsonschema 2.6.0
jupyter 1.0.0
jupyter-client 5.2.3
jupyter-console 5.2.0
jupyter-core 4.4.0
Keras 2.2.0
Keras-Applications 1.0.2
Keras-Preprocessing 1.0.1
kiwisolver 1.0.1
Markdown 2.6.11
MarkupSafe 1.0
matplotlib 2.2.2
mistune 0.8.3
nbconvert 5.3.1
nbformat 4.4.0
neo4j-driver 1.5.3
notebook 5.6.0
numpy 1.14.5
pandocfilters 1.4.2
parso 0.3.1
pexpect 4.6.0
pickleshare 0.7.4
pip 10.0.1
prometheus-client 0.3.0
prompt-toolkit 1.0.15
protobuf 3.6.0
ptyprocess 0.6.0
Pygments 2.2.0
pyparsing 2.2.0
python-dateutil 2.7.3
pytz 2018.5
PyYAML 3.13
pyzmq 17.1.0
qtconsole 4.3.1
scipy 1.1.0
Send2Trash 1.5.0
setuptools 39.0.1
simplegeneric 0.8.1
six 1.11.0
tensorboard 1.9.0
termcolor 1.1.0
terminado 0.8.1
testpath 0.3.1
tornado 5.1
traitlets 4.3.2
wcwidth 0.1.7
webencodings 0.5.1
Werkzeug 0.14.1
wheel 0.31.0
widgetsnbextension 3.3.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
HayashiyaKikuzo:~ xxx$ pip3 install --upgrade tensorflow・・・・再インストール
・・・・省略・・・・

 

 

  まとめ

とりあえず、サンプル通りではありますが TensorFlow / Keras を試すことが出来ました。

なお、実際にTensorFlow や Keras を使う上では、以下についても理解し何を分析するかなど決めておく必要がありそうです。

ニュートラルネットワーク

ディープラーニング

パーセプトロン

・ロジスティック回帰

・二値分類

多項式回帰

・線形回帰

などなど

 

 

オープンソース技研

www.slideshare.net

github.com

www.facebook.com

twitter.com

www.instagram.com

 

 

にほんブログ村 IT技術ブログ Linuxへ
Linux

にほんブログ村 IT技術ブログ オープンソースへ
オープンソース

 

bitFlyer ビットコインを始めるなら安心・安全な取引所で

ビットコイン取引高日本一の仮想通貨取引所 coincheck bitcoin

 

 

AIを学ぶ4 〜Jupyter Notebook を使ってみる〜

 

 

こんにちは、オープンソース技研鯨井貴博です。

 

今回は、AI(深層学習や機械学習)に利用できる Python統合開発環境である、

Jupyter Notebook 環境を用意します。

なお、操作は Mac OS上で行なっています。

 

 

pip3 を使用してインストール

pip3 からjupyter パッケージをインストールします。

なお、pip3が入っていない場合、以下を参照ください。

opensourcetech.hatenablog.jp

 

bash-3.2$ sudo pip3 install jupyter
Password:
The directory '/Users/********/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/********/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting jupyter
Downloading https://files.pythonhosted.org/packages/83/df/0f5dd132200728a86190397e1ea87cd76244e42d39ec5e88efd25b2abd7e/jupyter-1.0.0-py2.py3-none-any.whl
Collecting ipykernel (from jupyter)
Downloading https://files.pythonhosted.org/packages/ab/3f/cd624c835aa3336a9110d0a99e15070f343b881b7d651ab1375ef226a3ac/ipykernel-4.8.2-py3-none-any.whl (108kB)
100% |████████████████████████████████| 112kB 1.7MB/s
Collecting ipywidgets (from jupyter)
Downloading https://files.pythonhosted.org/packages/f0/5d/868df21e3b004a5a61294cab70e1f6f44986933eb3aa9c396dfd5112acb2/ipywidgets-7.3.0-py2.py3-none-any.whl (109kB)
100% |████████████████████████████████| 112kB 9.0MB/s
Collecting notebook (from jupyter)
Downloading https://files.pythonhosted.org/packages/5e/7c/7fd8e9584779d65dfcad9fa2e09c76131a41f999f853a9c7026ed8585586/notebook-5.6.0-py2.py3-none-any.whl (8.9MB)
100% |████████████████████████████████| 8.9MB 2.2MB/s
Collecting qtconsole (from jupyter)
Downloading https://files.pythonhosted.org/packages/90/ff/047e0dca2627b162866920e7aa93f04523c0ae81e5c67060eec85701992d/qtconsole-4.3.1-py2.py3-none-any.whl (108kB)
100% |████████████████████████████████| 112kB 10.0MB/s
Collecting nbconvert (from jupyter)
Downloading https://files.pythonhosted.org/packages/39/ea/280d6c0d92f8e3ca15fd798bbcc2ea141489f9539de7133d8fe10ea4b049/nbconvert-5.3.1-py2.py3-none-any.whl (387kB)
100% |████████████████████████████████| 389kB 6.9MB/s
Collecting jupyter-console (from jupyter)
Downloading https://files.pythonhosted.org/packages/77/82/6469cd7fccf7958cbe5dce2e623f1e3c5e27f1bb1ad36d90519bc2d5d370/jupyter_console-5.2.0-py2.py3-none-any.whl
Collecting jupyter-client (from ipykernel->jupyter)
Downloading https://files.pythonhosted.org/packages/94/dd/fe6c4d683b09eb05342bd2816b7779663f71762b4fa9c2d5203d35d17354/jupyter_client-5.2.3-py2.py3-none-any.whl (89kB)
100% |████████████████████████████████| 92kB 6.9MB/s
Requirement already satisfied: tornado>=4.0 in /usr/local/lib/python3.6/site-packages (from ipykernel->jupyter) (5.1)
Collecting traitlets>=4.1.0 (from ipykernel->jupyter)
Downloading https://files.pythonhosted.org/packages/93/d6/abcb22de61d78e2fc3959c964628a5771e47e7cc60d53e9342e21ed6cc9a/traitlets-4.3.2-py2.py3-none-any.whl (74kB)
100% |████████████████████████████████| 81kB 12.5MB/s
Collecting ipython>=4.0.0 (from ipykernel->jupyter)
Downloading https://files.pythonhosted.org/packages/b1/7f/91d50f28af3e3a24342561983a7857e399ce24093876e6970b986a0b6677/ipython-6.4.0-py3-none-any.whl (750kB)
100% |████████████████████████████████| 757kB 6.2MB/s
Collecting widgetsnbextension~=3.3.0 (from ipywidgets->jupyter)
Downloading https://files.pythonhosted.org/packages/b9/43/f6ff09448f7b961e102fd75b7e46a5d44b68b9746bb1ab5c4be64c3e236d/widgetsnbextension-3.3.0-py2.py3-none-any.whl (2.2MB)
100% |████████████████████████████████| 2.2MB 5.9MB/s
Collecting nbformat>=4.2.0 (from ipywidgets->jupyter)
Downloading https://files.pythonhosted.org/packages/da/27/9a654d2b6cc1eaa517d1c5a4405166c7f6d72f04f6e7eea41855fe808a46/nbformat-4.4.0-py2.py3-none-any.whl (155kB)
100% |████████████████████████████████| 163kB 8.8MB/s
Collecting terminado>=0.8.1 (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/2e/20/a26211a24425923d46e1213b376a6ee60dc30bcdf1b0c345e2c3769deb1c/terminado-0.8.1-py2.py3-none-any.whl
Collecting prometheus-client (from notebook->jupyter)
Collecting jinja2 (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
100% |████████████████████████████████| 133kB 11.4MB/s
Collecting Send2Trash (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/49/46/c3dc27481d1cc57b9385aff41c474ceb7714f7935b1247194adae45db714/Send2Trash-1.5.0-py3-none-any.whl
Collecting jupyter-core>=4.4.0 (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/1d/44/065d2d7bae7bebc06f1dd70d23c36da8c50c0f08b4236716743d706762a8/jupyter_core-4.4.0-py2.py3-none-any.whl (126kB)
100% |████████████████████████████████| 133kB 10.9MB/s
Collecting ipython-genutils (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting pyzmq>=17 (from notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/96/f9/b8641e4db55f5df80e0b0c15aaf2c177de2136c8c33b4ba518710ef0fe39/pyzmq-17.1.0-cp36-cp36m-macosx_10_6_intel.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 7.3MB/s
Requirement already satisfied: pygments in /usr/local/lib/python3.6/site-packages (from qtconsole->jupyter) (2.2.0)
Collecting pandocfilters>=1.4.1 (from nbconvert->jupyter)
Collecting entrypoints>=0.2.2 (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/cc/8b/4eefa9b47f1910b3d2081da67726b066e379b04ca897acfe9f92bac56147/entrypoints-0.2.3-py2.py3-none-any.whl
Collecting mistune>=0.7.4 (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/c8/8c/87f4d359438ba0321a2ae91936030110bfcc62fef752656321a72b8c1af9/mistune-0.8.3-py2.py3-none-any.whl
Collecting testpath (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/15/19/d7bc380c479a184e4a5a9ce516e4e2a773165f89b445f7cdced83d94de25/testpath-0.3.1-py2.py3-none-any.whl (161kB)
100% |████████████████████████████████| 163kB 8.3MB/s
Collecting bleach (from nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/30/b6/a8cffbb9ab4b62b557c22703163735210e9cd857d533740c64e1467d228e/bleach-2.1.3-py2.py3-none-any.whl
Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.0 in /usr/local/lib/python3.6/site-packages (from jupyter-console->jupyter) (1.0.15)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/site-packages (from jupyter-client->ipykernel->jupyter) (2.7.3)
Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from traitlets>=4.1.0->ipykernel->jupyter) (1.11.0)
Collecting decorator (from traitlets>=4.1.0->ipykernel->jupyter)
Downloading https://files.pythonhosted.org/packages/bc/bb/a24838832ba35baf52f32ab1a49b906b5f82fb7c76b2f6a7e35e140bac30/decorator-4.3.0-py2.py3-none-any.whl
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.6/site-packages (from ipython>=4.0.0->ipykernel->jupyter) (39.0.1)
Requirement already satisfied: backcall in /usr/local/lib/python3.6/site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.1.0)
Collecting simplegeneric>0.8 (from ipython>=4.0.0->ipykernel->jupyter)
Collecting pexpect; sys_platform != "win32" (from ipython>=4.0.0->ipykernel->jupyter)
Downloading https://files.pythonhosted.org/packages/89/e6/b5a1de8b0cc4e07ca1b305a4fcc3f9806025c1b651ea302646341222f88b/pexpect-4.6.0-py2.py3-none-any.whl (57kB)
100% |████████████████████████████████| 61kB 9.9MB/s
Requirement already satisfied: appnope; sys_platform == "darwin" in /usr/local/lib/python3.6/site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.1.0)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.6/site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.7.4)
Requirement already satisfied: jedi>=0.10 in /usr/local/lib/python3.6/site-packages (from ipython>=4.0.0->ipykernel->jupyter) (0.12.1)
Collecting jsonschema!=2.5.0,>=2.4 (from nbformat>=4.2.0->ipywidgets->jupyter)
Downloading https://files.pythonhosted.org/packages/77/de/47e35a97b2b05c2fadbec67d44cfcdcd09b8086951b331d82de90d2912da/jsonschema-2.6.0-py2.py3-none-any.whl
Collecting ptyprocess; os_name != "nt" (from terminado>=0.8.1->notebook->jupyter)
Downloading https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from jinja2->notebook->jupyter)
Collecting html5lib!=1.0b1,!=1.0b2,!=1.0b3,!=1.0b4,!=1.0b5,!=1.0b6,!=1.0b7,!=1.0b8,>=0.99999999pre (from bleach->nbconvert->jupyter)
Downloading https://files.pythonhosted.org/packages/a5/62/bbd2be0e7943ec8504b517e62bab011b4946e1258842bc159e5dfde15b96/html5lib-1.0.1-py2.py3-none-any.whl (117kB)
100% |████████████████████████████████| 122kB 15.7MB/s
Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/site-packages (from prompt-toolkit<2.0.0,>=1.0.0->jupyter-console->jupyter) (0.1.7)
Requirement already satisfied: parso>=0.3.0 in /usr/local/lib/python3.6/site-packages (from jedi>=0.10->ipython>=4.0.0->ipykernel->jupyter) (0.3.1)
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 https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
Installing collected packages: ipython-genutils, decorator, traitlets, jupyter-core, pyzmq, jupyter-client, simplegeneric, ptyprocess, pexpect, ipython, ipykernel, terminado, prometheus-client, jsonschema, nbformat, MarkupSafe, jinja2, pandocfilters, entrypoints, mistune, testpath, webencodings, html5lib, bleach, nbconvert, Send2Trash, notebook, widgetsnbextension, ipywidgets, qtconsole, jupyter-console, jupyter
Successfully installed MarkupSafe-1.0 Send2Trash-1.5.0 bleach-2.1.3 decorator-4.3.0 entrypoints-0.2.3 html5lib-1.0.1 ipykernel-4.8.2 ipython-6.4.0 ipython-genutils-0.2.0 ipywidgets-7.3.0 jinja2-2.10 jsonschema-2.6.0 jupyter-1.0.0 jupyter-client-5.2.3 jupyter-console-5.2.0 jupyter-core-4.4.0 mistune-0.8.3 nbconvert-5.3.1 nbformat-4.4.0 notebook-5.6.0 pandocfilters-1.4.2 pexpect-4.6.0 prometheus-client-0.3.0 ptyprocess-0.6.0 pyzmq-17.1.0 qtconsole-4.3.1 simplegeneric-0.8.1 terminado-0.8.1 testpath-0.3.1 traitlets-4.3.2 webencodings-0.5.1 widgetsnbextension-3.3.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
bash-3.2$ pip3 list
Package Version
------------------ -------
appnope 0.1.0
backcall 0.1.0
bleach 2.1.3
cycler 0.10.0
decorator 4.3.0
entrypoints 0.2.3
html5lib 1.0.1
ipykernel 4.8.2
ipython 6.4.0
ipython-genutils 0.2.0
ipywidgets 7.3.0
jedi 0.12.1
Jinja2 2.10
jsonschema 2.6.0
jupyter 1.0.0  <-------インストールされてますね!
jupyter-client 5.2.3
jupyter-console 5.2.0
jupyter-core 4.4.0
kiwisolver 1.0.1
MarkupSafe 1.0
matplotlib 2.2.2
mistune 0.8.3
nbconvert 5.3.1
nbformat 4.4.0
neo4j-driver 1.5.3
notebook 5.6.0
numpy 1.14.5
pandocfilters 1.4.2
parso 0.3.1
pexpect 4.6.0
pickleshare 0.7.4
pip 10.0.1
prometheus-client 0.3.0
prompt-toolkit 1.0.15
ptyprocess 0.6.0
Pygments 2.2.0
pyparsing 2.2.0
python-dateutil 2.7.3
pytz 2018.5
pyzmq 17.1.0
qtconsole 4.3.1
Send2Trash 1.5.0
setuptools 39.0.1
simplegeneric 0.8.1
six 1.11.0
terminado 0.8.1
testpath 0.3.1
tornado 5.1
traitlets 4.3.2
wcwidth 0.1.7
webencodings 0.5.1
wheel 0.31.0
widgetsnbextension 3.3.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

 

 Jupyter Notebook を起動する

ターミナルで、ファイル操作(pythonファイルの保存など)を行うディレクトリへ移動し、jupyter notebookを実行します。

bash-3.2$ cd /tmp
bash-3.2$ pwd
/tmp
bash-3.2$ jupyter notebook
[I 18:16:28.047 NotebookApp] Writing notebook server cookie secret to /Users/xxx/Library/Jupyter/runtime/notebook_cookie_secret
[I 18:16:28.887 NotebookApp] Serving notebooks from local directory: /private/tmp
[I 18:16:28.887 NotebookApp] The Jupyter Notebook is running at:
[I 18:16:28.887 NotebookApp] http://localhost:8888/?token=06c711274d041bd7b25c0065e1040515e7c83d2b01a403c1
[I 18:16:28.887 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:16:28.888 NotebookApp]

Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=06c711274d041bd7b25c0065e1040515e7c83d2b01a403c1
[I 18:16:29.258 NotebookApp] Accepting one-time-token-authenticated connection from ::1

 

すると、ブラウザが起動しJupyter Notebook 環境を使うことが出来ます。

 ※起動時にいたカレントディレクトリの内容が表示

f:id:opensourcetech:20180722183407p:plain

 Jupyter Notebook から Pythonを操作する

右側にある「New」からPython3を選択。

f:id:opensourcetech:20180722183447p:plain

新しくタブが開くなどし、緑で囲まれた箇所にPythonのプログラムを入力します。

f:id:opensourcetech:20180722183503p:plain

 

Numpyを使って足し算をしてみる例

※Outのところに、答えが帰されます。

f:id:opensourcetech:20180722183515p:plain

 

Pythonファイルの保存は、File > Save as... などから行います。

f:id:opensourcetech:20180722183546p:plain

f:id:opensourcetech:20180722183610p:plain

 

ディレクトリに、test.py が追加されました。

f:id:opensourcetech:20180722183621p:plain

 

ターミナルのログを見ても、上記の操作がされていることがわかります。

[I 18:19:16.591 NotebookApp] Creating new notebook in
[I 18:19:17.875 NotebookApp] Kernel started: 28b34ca8-c2f0-4eb0-acf0-e1c1ff76a01f
[I 18:19:19.564 NotebookApp] Adapting to protocol v5.1 for kernel 28b34ca8-c2f0-4eb0-acf0-e1c1ff76a01f
[W 18:21:53.809 NotebookApp] 404 GET /api/contents/test.py?type=notebook&content=0&_=1532251157154 (::1) 4.08ms referer=http://localhost:8888/notebooks/Untitled1.ipynb?kernel_name=python3
[I 18:21:53.818 NotebookApp] Uploading file to /test.py

 

 

 Jupyter Notebook を終了する

 ターミナルへ ctrl+c を入力します。

すると、以下のように終了するか(yes/no)を聞かれるので、

yを選択すると終了します。

[I 18:37:40.658 NotebookApp] interrupted
Serving notebooks from local directory: /private/tmp
2 active kernels
The Jupyter Notebook is running at:
http://localhost:8888/?token=06c711274d041bd7b25c0065e1040515e7c83d2b01a403c1
Shutdown this notebook server (y/[n])? y
[C 18:37:45.591 NotebookApp] Shutdown confirmed
[I 18:37:45.594 NotebookApp] Shutting down 2 kernels
[I 18:37:45.906 NotebookApp] Kernel shutdown: f20c1d6f-42c8-4c72-93bc-13e710f28fbd
[I 18:37:45.909 NotebookApp] Kernel shutdown: 28b34ca8-c2f0-4eb0-acf0-e1c1ff76a01f
bash-3.2$

 

 

 

 

オープンソース技研

www.slideshare.net

github.com

www.facebook.com

twitter.com

www.instagram.com

 

 

にほんブログ村 IT技術ブログ Linuxへ
Linux

にほんブログ村 IT技術ブログ オープンソースへ
オープンソース

 

bitFlyer ビットコインを始めるなら安心・安全な取引所で

ビットコイン取引高日本一の仮想通貨取引所 coincheck bitcoin

 

 

Opensourcetech by Takahiro Kujirai