環境

    • Python 3.5.2

 

    • matplotlib 1.5.3

 

    • ipython 5.1.0

 

    • jupyter 4.2.0

 

    • vagrant

 

    CentOS7.1

関連記事

python(pyenv)インストールメモ

Jupyter LabをDockerで環境構築する

    Jupyter LabをDockerで環境構築する

Vagrantで環境構築する場合

install matplotlib

$ pip install matplotlib

install jupyter

$ pip install jupyter

vagrant sshでポートフォワーディング設定

PCのブラウザから、vagrant上のjupyterにアクセスするためポートフォワーディングさせる。

$ vagrant ssh -- -L 8888:localhost:8888

それか、Vagrantfileに以下を追記

Vagrant.configure("2") do |config|
  # *snip*
  config.vm.network "forwarded_port", guest: 8888, host: 8888
  # *snip*
end

jupyterを起動

–ip=0.0.0.0 はlocalhost以外でのアクセスをする場合に必要。

$ jupyter notebook --no-browser --ip=0.0.0.0

もしくは

$ ipython notebook --no-browser --ip=0.0.0.0

ブラウザからjupyter-notebookへアクセス

http://localhost:8888
もしくはvagrantのIPアドレスでアクセス
http://192.168.33.10:8888

581d5c.png
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-3, 3, 0.1)
y = np.sin(x)
plt.plot(x, y)
9bd360.png

No module named _tkinterとかtkinter関連のエラーが出る場合はこちらを参照
matplotlib使うなら下記も先にインストール

以上

[参考]
vagrant で ipython notebook 環境を構築した話
vagrantで作ったVMでipython notebookを立ち上げてローカルからアクセスする
jupyter (ipython) notebook でグラフが出ない時の対応方法

bannerAds