LoginSignup
35
42

More than 5 years have passed since last update.

(備忘録)Ubuntu 18.04 LTS で Jupyter Notebook 環境構築

Last updated at Posted at 2019-04-09

1. はじめに

Python + openCV を用いたハンズオンへの参加条件を満たすために、Ubuntu18.04LTSにJupyter Notebook 環境を構築した際のメモを、自分への備忘録としてまとめてみました。ご参考になれば幸いです。

2. 学べる内容

  • Python2系のインストール
  • Python3系のインストール
  • Jupyter Notebookのインストール
  • chainerとTendsorFlowのインストール
  • opencvとnumpyのインストール
  • Jupyter Notebookの起動

3. インストール

Ubuntuプロンプト
# Python2系のインストール
$ sudo apt install python-pip python-pandas python-sklearn

# Python3系のインストール
$ sudo apt install python3-pip python3-pandas python3-sklearn

# Jupyter Notebookのインストール
$ sudo apt install jupyter-notebook

# chainerとTendsorFlowのインストール(Python2系)
$ sudo pip install chainer tensorflow pandas-ml

# chainerとTendsorFlowのインストール(Python3系)
$ sudo pip3 install chainer tensorflow pandas-ml

# opencvとnumpyのインストール(Python2系)
$ pip install opencv-python

# opencvとnumpyのインストール(Python3系)
$ pip3 install opencv-python

4. Jupyter Notebookの起動

Ubuntuプロンプト
# Jupyter Notebookの起動(自動的にブラウザが立ち上がりJupyter Notebookが起動する)
$ jupyter-notebook

Jupter.PNG

  • Jupyter Notebookの起動後は、「New」のドロップダウンリストから「Python3」を選択すれば見慣れた画面が表示されると思います。
  • ブラウザのアクセスURLは、http://localhost:8888/tree となるようです。

5. 動作確認用コード

# ライブラリのインポート
import sys
import pprint

// パス確認
pprint.pprint(sys.path)

# ライブラリのインポート
import cv2                       # OpenCV
import numpy as np               # numpy
import matplotlib.pyplot as plt  # 画像表示ライブラリ

# jupyter notebook 上で画像を確認できるようにする
%matplotlib inline

# cv2バージョン確認
cv2.__version__

# 表示画像の作成
img2 = np.array([[[  0,  0,  0],[  0,  0,255],[  0,255,  0],[255,  0,  0]],
                 [[  0,255,255],[255,  0,255],[255,255,  0],[255,255,255]]])
img2 = img2.astype(np.uint8) # 値を読み込む方法を指定
print(type(img2))

# 画像表示
plt.imshow(img2)

コメント 2019-04-13 005036.jpg

6. 補足

  • Jupyter Notebook の実行環境にはこだわりがなく、とにかく Jupyter Notebook をさわってみたいという方には、Google Colaboratory をおすすめします。
  • Google Colaboratory なら環境構築不要で Jupyter Notebook が使えます。しかもちょこっと設定をするとGPUもつかえますので、Pythonのお勉強環境にもってこいです。

7. おわりに

PythonおよびJupyter Notebook学習の参考になれば幸いです。

2019/04/09 TAKAHIRO NISHIZONO

35
42
3

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
35
42