#Chainerは入るけど,import cupyするとエラーが出る
Linux環境下に,CUDA-7.5を入れたのち,
gcc 8.4.5,pipを使って,
$ pip install chainer
すると,
$ Successfully installed chainer-1.20.0.1
と出るのに,いざcupyを読み込もうとimport cupyすると正常に読み込めない.
Traceback (most recent call last):
File "./train_mnist.py", line 107, in <module>
main()
File "./train_mnist.py", line 56, in main
chainer.cuda.get_device(args.gpu).use() # Make a specified GPU current
File "C:\Program Files\Anaconda3\lib\site-packages\chainer\cuda.py", line 167, in get_device
check_cuda_available()
File "C:\Program Files\Anaconda3\lib\site-packages\chainer\cuda.py", line 85, in check_cuda_available
raise RuntimeError(msg)
RuntimeError: CUDA environment is not correctly set up
(see https://github.com/pfnet/chainer#installation).CuPy is not correctly installed. Please check your environment, uninstall Chainer and reinstall it with `pip install chainer --no-cache-dir -vvvv`.
う〜ん,仕方がないので,
$ pip uninstall chainer
$ pip install chainer --no-cache-dir -vvvv
とすると,CUDAはスキップしてますの文字が.
/usr/bin/ld: cannot find -lcuda
collect2: error: ld returned 1 exit status
Cannot build a stub file.
Original error: command 'g++' failed with exit status 1
**************************************************
*** WARNING: Cannot link libraries: ['cublas', 'cuda', 'cudart', 'curand', 'nvToolsExt']
*** WARNING: Skip installing cuda support
*** WARNING: Check your LDFLAGS environment variable
**************************************************
Include directories: ['/usr/local/cuda/include']
Library directories: ['/usr/local/cuda/lib64', '/usr/local/cuda/lib']
ところが,LDFLAGSを見ても変ではないので,なぜだろうと格闘するも・・・入らない.
よ〜くエラーを見ると,その上のあたりでlibcuda.soがないと言われている.
/usr/bin/ld: cannot find -lcuda
まさかと思って,/usr/local/cuda/lib64と/usr/local/cuda/libを見に行くと・・・ない!
探したところ,まさかの/usr/local/cuda/lib64/stubsにいらっしゃる.
そこで,ビルド時にgccが見に行くLIBRARY_PATHにこのフォルダを通してやる.
$ export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64
$ export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib
$ export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64/stubs
それで再び
$ pip install chainer --no-cache-dir -vvvv
すると,WARNINGが出なくなったぞ!!!!
#しかしそのままだと足りない
ところが,万を辞してcupyを読み込むと,
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/slab/hirohara/.pyenv/versions/anaconda2-4.1.1/lib/python2.7/site-packages/cupy/__init__.py", line 18, in <module>
raise six.reraise(RuntimeError, RuntimeError(msg), exc_info[2])
File "/home/slab/hirohara/.pyenv/versions/anaconda2-4.1.1/lib/python2.7/site-packages/cupy/__init__.py", line 7, in <module>
from cupy import core # NOQA
File "/home/slab/hirohara/.pyenv/versions/anaconda2-4.1.1/lib/python2.7/site-packages/cupy/core/__init__.py", line 1, in <module>
from cupy.core import core # NOQA
RuntimeError: CuPy is not correctly installed. Please check your environment, uninstall Chainer and reinstall it with `pip install chainer --no-cache-dir -vvvv`.
original error: libcuda.so.1: cannot open shared object file: No such file or directory
また怒られる.libcuda.so.1がないらしい.検索しても確かにない.そこで,libcuda.soからシンボリックリンクを貼ってやることにする.
$ cd /usr/local/cuda/lib64/stubs/
$ ln -s libcuda.so libcuda.so.1
で,先ほどと同じように,これのディレクトリを実行時にライブラリを読み込むLD_LIBRARY_PATHに通してやる.
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/stubs
これで,import cupyすると・・・できた!!!できた!!!!