LoginSignup
7
9

More than 5 years have passed since last update.

[Python][Chainer][Windows] WindowsにChainerのインストール

Last updated at Posted at 2016-07-06

WindowsでのChainer環境作成手順メモ(主にエラーの対処に関する備忘録です)

Chainer: A flexible framework for neural networks

※注意! 筆者の環境ではGPU使用版(CUDA版)の実行環境が作成できなかったため、CPU版での参考としてください

検証環境

  • Windows 10
  • Python 3.6.0
  • Chainer 1.21.0
  • CUDA 8
  • GeForce GTX 760

インストール手順

(Option) CUDA Toolkitのインストール

ChainerでCUDAを使用したい場合は、必ず先に CUDA Toolkit をインストールしてください

CUDA Toolkit | NVIDIA Developer

例:[Download] => [Windows] => [x86_64] => [10] => [exe (network)] を選択。

Chainerのインストール

Chainerをインストールします。

$ pip install chainer

サンプルの動作確認

※実行するサンプルを落としてくる際には、masterではなく、必ず落としてきたChainerと同じバージョンのタグのサンプルを使用してください。(バージョン不一致の場合エラーが出る可能性があります)

pfnet/chainer: A flexible framework of neural networks for deep learning

通常での実行

通常での実行
$ python examples/mnist/train_mnist.py

無題.png

GPUを使った実行

TODO: 自分の環境だとどうも実行時にエラーがでるので検証中
=> 他の人の記事を真似して試行錯誤しても、CUDAのヘッダー類をどうやっても検出できないため諦め中・・・(v1.21.0)。

インストールが成功していれば以下の実行が可能なはずです。

gpuを使用した実行
$ python train_mnist.py -g 0

トラブルシューティング

Microsoft Visual C++ 14.0が存在しない場合

補足: すでに Visual Studio 2015 をインストール済みの環境ではこのエラーは発生しませんでした。

pipでインストールしようとすると以下の様なエラーがでました。

pipでchainerのインストールを実行して失敗
$ pip install chainer
  Using cached chainer-1.10.0.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info\chainer.egg-info
    writing top-level names to pip-egg-info\chainer.egg-info\top_level.txt
    writing dependency_links to pip-egg-info\chainer.egg-info\dependency_links.txt
    writing pip-egg-info\chainer.egg-info\PKG-INFO
    writing requirements to pip-egg-info\chainer.egg-info\requires.txt
    writing manifest file 'pip-egg-info\chainer.egg-info\SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
    Executing cythonize
    Options: {'annotate': False, 'no_cuda': False, 'profile': False, 'linetrace': False}
    **************************************************
    *** WARNING: nvcc not in path.
    *** WARNING: Please set path to nvcc.
    **************************************************
    Include directories: []
    Library directories: []

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\<username>\AppData\Local\Temp\pip-build-7ak65o9t\chainer\

どうやらCythonのためのコンパイラがないのでダメな様子なので、エラーログにも指定されている Microsoft Visual C++ Build Tools を先にインストールします。(環境にもよるとは思いますが、インストールに地味に時間がかかりました。30分ぐらい?)

Download the Visual C++ Build Tools (standalone C++ compiler, libraries and tools)

これでもう一度実行すればインストールできるはずです。

サンプル実行時に AttributeError: 'module' object has no attribute 'PlotReport' となる

上にも書きましたが、インストールしたChainerのバージョンとサンプルのバージョンが一致しない場合にこのエラーがでました。
自分のケースでは chainer 1.21.0 使用時に master を使用してしまい、このエラーが発生しました。
対処としては、1.21.0 のタグをチェックアウトして、そのバージョンでのサンプルを使用すれば問題なく動作しました。

cuda.h などが見つからない(未解決)

chainer のインストール時に以下のエラーが出るケースがあります。

**************************************************
*** WARNING: Include files not found: ['cublas_v2.h', 'cuda.h', 'cuda_profiler_api.h', 'cuda_runtime.h', 'curand.h']
*** WARNING: Skip installing cuda support
*** WARNING: Check your CFLAGS environment variable
**************************************************

TODO: 現状筆者の環境では未解決です・・・。他の人の記事ではINCLUDEにパスを足すなどの記載がありましたので足してみましたが解決しませんでした。

cudnn.h が見つからない(未検証)

**************************************************
*** WARNING: Include files not found: ['cudnn.h']
*** WARNING: Skip installing cudnn support
*** WARNING: Check your CFLAGS environment variable
**************************************************

参考

Chainer MNIST Error AttributeError: 'module' object has no attribute 'PlotReport'
Windows10にChainer+CUDA 8.0をインストール - Qiita

7
9
2

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
9