3

我在 python2.7.11 中有一个使用chainer 和cupy 的项目。将 Chainer 版本从 1.22 更新到 4.1.0 后,我无法使用 cupy

>>> import cupy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cupy

这是我安装chainer1.22的方式。无需安装cupy即可成功导入cupy。

pip install chainer==1.22,

查看

>>> import chainer
>>> import cupy
>>> chainer.cuda.available
True

我可以看到 CUDA 可用于chainer1.22

所以我卸载了chainer 1.22

pip uninstall chainer

安装chainer 4.1.0

pip install chainer==4.1.0

结果是

>>> import chainer
>>> import cupy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cupy
>>> chainer.cuda.available
False

可以看到 cuda 不适用于 chainer 版本 4.1.0。所以我尝试用 pip 安装 cupy

pip install cupy

安装时记录

Requirement already satisfied: numpy>=1.9.0 in c:\users\UserName\appdata\local\continuum\anaconda2\lib\site-packages (from cupy)
Requirement already satisfied: six>=1.9.0 in c:\users\UserName\appdata\local\continuum\anaconda2\lib\site-packages (from cupy)
Requirement already satisfied: fastrlock>=0.3 in c:\users\UserName\appdata\local\continuum\anaconda2\lib\site-packages (from cupy)
Building wheels for collected packages: cupy
  Running setup.py bdist_wheel for cupy ... /
.
.
.
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.

  tmpxft_000027f8_00000000-1.cpp
  nvcc fatal   : Host compiler targets unsupported OS.
  error: command 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\bin/nvcc.exe' failed with exit status 1

  ----------------------------------------
  Failed building wheel for cupy
  Running setup.py clean for cupy
Failed to build cupy
Installing collected packages: cupy
.
.
.
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64
    Copyright (C) Microsoft Corporation.  All rights reserved.

    tmpxft_0000456c_00000000-1.cpp
    nvcc fatal   : Host compiler targets unsupported OS.
    error: command 'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\bin/nvcc.exe' failed with exit status 1

    ----------------------------------------
Command "C:\Users\UserName\AppData\Local\Continuum\Anaconda2\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\UserName\\appdata\\local\\temp\\pip-build-gwroh2\\cupy\\setup.py';
f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();
exec(compile(code, __file__, 'exec'))" install --record c:\users\UserName\appdata\local\temp\pip-tbtixt-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\UserName\appdata\local\temp\pip-build-gwroh2\cupy\

无法构建 cupy 我检查了 nvcc 版本

nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Mon_Jan__9_17:32:33_CST_2017
Cuda compilation tools, release 8.0, V8.0.60

当我尝试在chainer1.22环境下通过pip安装cupy时,也会出现同样的问题

这是我的环境

Windows 10 pro 64bit
Anaconda 2.4.11
NVDIA GTX 1060 6GB, Driver Version: 398.11
CUDA 8.0
Visual studio 2015

我引用了这篇文章 ,但它对我不起作用。

如何使用 CHAINER4.1.0 导入 CUPY?

感谢您阅读我的问题!

4

3 回答 3

3

据我所知,chainer version 2之后chainer和cupy是分开的。所以cupy是随chainer version 1自动安装的,但是在chainer version 2之后需要单独安装cupy。所以需要安装cupy但我不知道构建失败的原因。

如果你能理解你正在使用的 CUDA 版本,你可以从构建的包中安装,cupy-cudaXX其中 XX 代表你的 CUDA 版本。试试下面:

# make sure cupy is uninstalled
pip uninstall cupy
pip uninstall cupy
# based on the cuda version, install command changes.
# Ex. CUDA version is 8.0
pip install cupy-cuda80
# Ex2. CUDA version is 9.0
# pip install cupy-cuda90
于 2018-06-22T09:11:23.257 回答
3

尝试

pip install -U pip setuptools
pip freeze
pip uninstall chainer cupy cupy-cuda80 cupy-cuda90 cupy-cuda91 cupy-cuda92
pip install --no-cache-dir cupy-cuda80
于 2018-07-09T01:57:46.620 回答
0

我最近在 windows 环境 python 3.6 vs 2015 cuda 8.0 上遇到了这个错误。我试过了

点安装cupy

但它没有安装软件包。我想是因为对于cupy,由于兼容性问题,我们不得不提到cuda版本。然而,进入

pip install cupy--cuda80

正确安装了软件包。

于 2018-10-02T12:13:20.237 回答