LoginSignup
7
11

More than 5 years have passed since last update.

機械学習の勉強会のためにPyData環境の構築を行う (2017年1月)

Last updated at Posted at 2017-01-05

前提条件

Python機械学習プログラミング(インプレス) を題材に内輪で勉強会を行う事になりました。
Python 3.6 もリリースされたこともあるので、改めて環境構築方法をまとめます。

ここで行う環境構築は、以下のとおりです。

  • VirtualBox + Vagrant
  • Ubuntu 16.04 LTS
  • Python 3.6
  • PyData関連(NumPy/Pandas/scikit-learn(sklearn))

以下は導入済みとします。

  • VirtualBox (5.0.30)
  • Vagrant (1.9.1)
$ VirtualBox --help
Oracle VM VirtualBox Manager 5.0.30

$ vagrant version
Installed Version: 1.9.1
Latest Version: 1.9.1

VirtualBox + Vagrant

Vagrant用のフォルダを準備。今回は、機械学習の勉強をするので、 ~/vagrant/ml-study というフォルダを準備して環境等を整える。

$ mkdir ~/vagrant/ml-study

Vagrant Box の追加

$ vagrant box add ubuntu/xenial64 https://atlas.hashicorp.com/ubuntu/boxes/xenial64/versions/20170104.0.0/providers/virtualbox.box

Vagrant 起動

$ vagrant init ubuntu/xenial64
$ vagrant up

Vagrant設定 (Vagrantfileを編集)
最下部の config.vm.provision を有効にして以下のように記述する

...
  config.vm.provision "shell", inline: <<-SHELL
    apt-get update
    sudo apt-get install -y build-essential libssl-dev libxml2-dev libxslt1-dev libbz2-dev zlib1g-dev python-setuptools python-dev libjpeg62-dev libreadline-gplv2-dev
    sudo apt-get install -y libblas-dev liblas-dev liblapack-dev gfortran libfreetype6-dev
  SHELL
...

設定の反映

$ vagrant provision

OSの関連パッケージ

Vagrantfile に必要なパッケージを記述したので、vagrant側でインストール済みとなる。

Python 3.6

$ mkdir ~/tmp
$ sudo mkdir /opt/python36
$ sudo chown ubuntu /opt/python36
$ cd tmp
$ wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
$ tar zxvf Python-3.6.0.tgz
$ cd Python-3.6.0/
$ ./configure --prefix=/opt/python36
$ make && make install
$ cd ~
$ /opt/python36/bin/python3 -m venv python
$ source python/bin/activate

Pythonの関連モジュール

$ pip install numpy scipy pandas scikit-learn matplotlib
$ pip install ipython[notebook]
$ pip install seaborn
$ pip install pyprind

設定後に使う時

$ cd ~/vagrant/ml-study
$ vagrant up
$ vagrant ssh
$ cd ~
$ source python/bin/activate
$ jupyter notebook

停止時

$ vagrant halt

jupyter notebook の設定

(2017年1月8日追記)

ホストマシンからブラウザで直接Jupyter notebookにアクセスしようとすると、IP制限で拒否されてしまう。以下の設定を行うことで、IP制限を解除できる。

$ source python/bin/activate
$ jupyter notebook --generate-config
~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip = '*'
7
11
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
7
11