安装带有cupy的pip包作为要求会使安装进入永无止境的循环



我正在尝试制作一个将cupy作为要求之一的pip包,但我在要求中包含cupy,pip安装最终进入了一个永无止境的循环。我正在尝试在Google Colab上安装该软件包,该软件包已经安装了Cupy,因此它应该只检查Cupy是否已安装,而不是尝试再次安装它。

我在github中制作了一个最小的pip包,其中cupy是唯一的要求。

https://github.com/Santosh-Gupta/TroubleShootCupyInstall

我试图在谷歌Colab中安装它

!pip install --verbose https://github.com/Santosh-Gupta/TroubleShootCupyInstall/archive/master.zip --log 'file.log'

输出很多,因为它是冗长的,但这些是当它进入循环时打印的行。

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -D_FORCE_INLINES=1 -I/usr/local/cuda/include -I/usr/include/python3.6m -c cupy/cuda/nvtx.cpp -o build/temp.linux-x86_64-3.6/cupy/cuda/nvtx.o
x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/cupy/cuda/nvtx.o -L/usr/local/cuda/lib64 -lnvToolsExt -o build/lib.linux-x86_64-3.6/cupy/cuda/nvtx.cpython-36m-x86_64-linux-gnu.so -Wl,--disable-new-dtags,-rpath,/usr/local/cuda/lib64
building 'cupy.cuda.thrust' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -D_FORCE_INLINES=1 -I/usr/local/cuda/include -I/usr/include/python3.6m -c cupy/cuda/thrust.cpp -o build/temp.linux-x86_64-3.6/cupy/cuda/thrust.o
NVCC options: ['--generate-code=arch=compute_30,code=compute_30', '--generate-code=arch=compute_50,code=compute_50', '--generate-code=arch=compute_60,code=sm_60', '--generate-code=arch=compute_61,code=sm_61', '--generate-code=arch=compute_70,code=sm_70', '--generate-code=arch=compute_75,code=sm_75', '--generate-code=arch=compute_70,code=compute_70', '-O2', '--compiler-options="-fPIC"']
/usr/local/cuda/bin/nvcc -D_FORCE_INLINES=1 -I/usr/local/cuda/include -I/usr/include/python3.6m -c cupy/cuda/cupy_thrust.cu -o build/temp.linux-x86_64-3.6/cupy/cuda/cupy_thrust.o --generate-code=arch=compute_30,code=compute_30 --generate-code=arch=compute_50,code=compute_50 --generate-code=arch=compute_60,code=sm_60 --generate-code=arch=compute_61,code=sm_61 --generate-code=arch=compute_70,code=sm_70 --generate-code=arch=compute_75,code=sm_75 --generate-code=arch=compute_70,code=compute_70 -O2 --compiler-options="-fPIC"

为了方便起见,我制作了一个运行此行的Google Colab笔记本,并具有完整的输出。

https://colab.research.google.com/drive/1DFR78cJ07KaHkJfpjh8370SxNw0HXI50

CuPy 目前提供名为cupy的源码包和名为cupy-cudaXX的二进制分发包(其中 XX 是 CUDA 版本(。 目前,Google Colab 附带cupy-cuda100,因为它使用的是 CUDA 10.0。 如果将cupy指定为包的要求,则将下载并安装cupy源包(需要几分钟的构建(,即使 CuPy 已通过cupy-cuda100提供。

不幸的是,Python 包分发工具(如setuptoolspip等(并没有提供一种很好地处理这种复杂包组合的方法。

解决方法 1

setup.py(或包裹的__init__.py(

try:
import cupy
except Exception:
raise RuntimeError('CuPy is not available. Please install it manually: https://docs-cupy.chainer.org/en/stable/install.html#install-cupy')
# You can also use `cupy.__version__` and `numpy.lib.NumpyVersion` to test CuPy version requirement here.

解决方法 2

使用pkg_resources(setuptools的一部分(手动检查需求,就像在 Chainer 中所做的那样。

  • https://github.com/chainer/chainer/blob/v6.3.0/chainer/_environment_check.py#L44
  • https://github.com/chainer/chainer/blob/v6.3.0/chainer/_version.py#L4-L18

最新更新