Help us understand the problem. What is going on with this article?

[メモ] Vagrantで、Jupyter Notebook

More than 3 years have passed since last update.

概要

  • Jupyter Notebookを、Vagrantで、さくっと動かす。
  • Python2でJupyterNotebookを動かして、Python3のカーネル追加。
    (Vagrantfileをちょこっと書き換えれば、反対もできるよ)
  • 作成したノートは、ホストのnotebookフォルダの中にできる、ハズ。(VMの/vagrant/notebook)

環境

手順

  1. 適当なフォルダに、Vagrantfileを作成
    - 'your_token_here'のとこを編集する。(平文パスワード)
    - aptキャッシュサーバがあれば、その辺も編集

    Vagrantfile
    # Vagrantfile
    # - Replace 'your_token_here' with yours :-)
    
    VB_NAME="Jupyter Notebook"
    VM_MEMORY=1024
    VM_CORES=2
    
    Vagrant.configure("2") do |config|
        config.vm.box = "bento/ubuntu-16.04"
        config.vm.network "forwarded_port", guest: 8888, host: 8888
        config.vm.provider "virtualbox" do |vb|
            #   vb.gui = true
            vb.name = VB_NAME
            vb.memory = VM_MEMORY
            vb.cpus = VM_CORES
        end
    
        config.vm.provision "shell", inline: <<-SHELL
            #whoami # => root
            #echo 'Acquire::http::Proxy "http://apt_cache_server:3142";' | tee /etc/apt/apt.conf.d/02proxy
            #
            apt-get -q update -q
            #DEBIAN_FRONTEND=noninteractive apt-get -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
            #
            # Jupyter on Python2
            apt-get -q install -q -y python-dev python-pip
            pip install --upgrade pip
            pip install --upgrade jupyter
            #
            # Python3 kernel
            apt-get -q install -q -y python3-dev python3-pip
            pip3 install --upgrade pip
            python3 -m pip install ipykernel
            python3 -m ipykernel install
            #
            mkdir -p /vagrant/notebook
            apt-get autoremove -y ; apt-get clean
        SHELL
    
        config.vm.provision "shell", privileged: false, inline: <<-SHELL
            #whoami # => vagrant 
            jupyter notebook --generate-config -y
            echo "c.NotebookApp.token = 'your_token_here'" >> $HOME/.jupyter/jupyter_notebook_config.py
        SHELL
    
        config.vm.provision "shell", privileged: false, run: "always", inline: <<-SHELL
            #whoami # => vagrant 
            jupyter notebook --notebook-dir=/vagrant/notebook --no-browser --ip=0.0.0.0 2>&1 &
        SHELL
    end
    
  2. vagrant up
    待つ

  3. ブラウザを起動して、http://localhost:8888/にアクセス。
    - tokenを聞かれたら、↑で設定したのを入れる。
    - token設定は、/home/vagrant/.jupyter/jupyter_notebook_config.pyの最後の行にあるハズ.

その他

  1. githubにおいた.

    こぴぺ(自分用)
    mkdir /c/Vagrant/Jupyter
    cd /c/Vagrant/Jupyter
    curl https://raw.githubusercontent.com/mt08xx/Vagrantfiles/master/Jupyter/Vagrantfile | sed -e 's/your_token_here/password/g' -e "s/#echo '/echo '/g" -e 's/apt-cache-server/linux64/g' > Vagrantfile
    time vagrant up
    
  2. 時間計測

    SSD+aptキャッシュあり。
    time vagrant up
    .
    .
    .
    real    16m30.540s
    user    0m0.000s
    sys     0m0.031s
    
mt08
ツイッターアカウントと紐づけてみた。[2019-11-26]
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした