Introduction

会社でChainerを使う案件が来ました。まずは環境構築から実施。

2018/11/01 更新
仮想環境はcondaを使わない方が良いです。condaの仮想環境ではpipでインストールしたパッケージを全ての環境で共有してしまうからです。
正しい仮想環境の作成は開発メモ その143 Pythonの仮想環境を正しく使うを参考にして下さい。

Resolution

Anaconda はインストール済みであるとします。
また、condaの仮想環境は作成済みとします。
下記のような感じで作成し、仮想環境に入ります。

1
2
conda create -n chainer python=3.6
conda activate chainer

仮想環境に入ったら下記のようにしてCuPyChainerをインストールします。
最後に、GPUとの接続を確認しています。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(D:\Works\Python\Envs\chainer) C:\Users\TAKUYA>pip install cupy
Collecting cupy
Downloading https://files.pythonhosted.org/packages/ab/fc/7aee3fe0c2aa7e57de873f35f275b8afb434c091f9b555582418b18a238c/cupy-4.5.0.tar.gz (2.1MB)
100% |████████████████████████████████| 2.1MB 2.2MB/s
Requirement already satisfied: numpy>=1.9.0 in d:\works\python\envs\chainer\lib\site-packages (from cupy) (1.15.2)
Requirement already satisfied: six>=1.9.0 in c:\users\takuya\appdata\roaming\python\python36\site-packages (from cupy) (1.11.0)
Collecting fastrlock>=0.3 (from cupy)
Downloading https://files.pythonhosted.org/packages/8f/ff/6777b85fdbc6efd572a2b713e044c29f5f01ca8b1c74f8d94b427bac60c3/fastrlock-0.4.tar.gz (47kB)
100% |████████████████████████████████| 51kB 2.2MB/s
Building wheels for collected packages: cupy, fastrlock
Running setup.py bdist_wheel for cupy ... done
Stored in directory: C:\Users\TAKUYA\AppData\Local\pip\Cache\wheels\28\7e\d8\c2c115fd4d5377490c8679258673630e53df1de49a6aa522ad
Running setup.py bdist_wheel for fastrlock ... done
Stored in directory: C:\Users\TAKUYA\AppData\Local\pip\Cache\wheels\73\2b\fe\8bdf21b8ebdc58dfafa3a0935767d2ae9c8f68e49d04c5a190
Successfully built cupy fastrlock
Installing collected packages: fastrlock, cupy
Successfully installed cupy-4.5.0 fastrlock-0.4

(D:\Works\Python\Envs\chainer) C:\Users\TAKUYA>pip install chainer
Collecting chainer
Downloading https://files.pythonhosted.org/packages/fc/ae/5b08a1717187ef98127b5d68ec700009b9c8a918b40319813e3e89f2254f/chainer-4.5.0.tar.gz (402kB)
100% |████████████████████████████████| 409kB 8.5MB/s
Collecting filelock (from chainer)
Downloading https://files.pythonhosted.org/packages/b4/fe/5ca16d167849b980925d3bd706cda266c7435dcf21675c546374da207654/filelock-3.0.9-py3-none-any.whl
Requirement already satisfied: numpy>=1.9.0 in d:\works\python\envs\chainer\lib\site-packages (from chainer) (1.15.2)
Collecting protobuf>=3.0.0 (from chainer)
Downloading https://files.pythonhosted.org/packages/e8/df/d606d07cff0fc8d22abcc54006c0247002d11a7f2d218eb008d48e76851d/protobuf-3.6.1-cp36-cp36m-win_amd64.whl (1.1MB)
100% |████████████████████████████████| 1.1MB 1.9MB/s
Requirement already satisfied: six>=1.9.0 in c:\users\takuya\appdata\roaming\python\python36\site-packages (from chainer) (1.11.0)
Requirement already satisfied: cupy<5.0.0,>=4.4.0 in d:\works\python\envs\chainer\lib\site-packages (from chainer) (4.5.0)
Requirement already satisfied: setuptools in d:\works\python\envs\chainer\lib\site-packages (from protobuf>=3.0.0->chainer) (40.4.3)
Requirement already satisfied: fastrlock>=0.3 in d:\works\python\envs\chainer\lib\site-packages (from cupy<5.0.0,>=4.4.0->chainer) (0.4)
Building wheels for collected packages: chainer
Running setup.py bdist_wheel for chainer ... done
Stored in directory: C:\Users\TAKUYA\AppData\Local\pip\Cache\wheels\4f\a5\e6\b0cbcc4cc1daeaab566096480d5b9aed9106de601daf1006f8
Successfully built chainer
Installing collected packages: filelock, protobuf, chainer
Successfully installed chainer-4.5.0 filelock-3.0.9 protobuf-3.6.1

(D:\Works\Python\Envs\chainer) C:\Users\TAKUYA>python -c "import chainer; print(chainer.cuda.available)"
True