无法在 Google Colab 上安装 CuPy 12.2.0

问题描述 投票:0回答:1

我想在 Colab 上使用 CuPy 12.2.0,但 Colab 上安装的默认 CuPy 版本是 11.0.0。 我尝试了多种方法安装12.2.0版本,均失败。

  1. 当我尝试使用命令
    pip install cupy-cuda12x
    安装 cupy 并将 cupy 导入为
    import cupy
    时,我收到了以下消息。
/usr/local/lib/python3.10/dist-packages/cupy/_environment.py:447: UserWarning: 
--------------------------------------------------------------------------------

  CuPy may not function correctly because multiple CuPy packages are installed
  in your environment:

    cupy-cuda11x, cupy-cuda12x

  Follow these steps to resolve this issue:

    1. For all packages listed above, run the following command to remove all
       existing CuPy installations:

         $ pip uninstall <package_name>

      If you previously installed CuPy via conda, also run the following:

         $ conda uninstall cupy

    2. Install the appropriate CuPy package.
       Refer to the Installation Guide for detailed instructions.

         https://docs.cupy.dev/en/stable/install.html

--------------------------------------------------------------------------------

  warnings.warn(f'''
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/cupy/__init__.py in <module>
     16 try:
---> 17     from cupy import _core  # NOQA
     18 except ImportError as exc:

/usr/local/lib/python3.10/dist-packages/cupy/_core/__init__.py in <module>
      2 
----> 3 from cupy._core import core  # NOQA
      4 from cupy._core import fusion  # NOQA

ImportError: libcudart.so.12: cannot open shared object file: No such file or directory

The above exception was the direct cause of the following exception:

ImportError                               Traceback (most recent call last)
<ipython-input-2-329ec5cf1bc8> in <cell line: 1>()
----> 1 import cupy

/usr/local/lib/python3.10/dist-packages/cupy/__init__.py in <module>
     17     from cupy import _core  # NOQA
     18 except ImportError as exc:
---> 19     raise ImportError(f'''
     20 ================================================================
     21 {_environment._diagnose_import_error()}

ImportError: 
================================================================
Failed to import CuPy.

If you installed CuPy via wheels (cupy-cudaXXX or cupy-rocm-X-X), make sure that the package matches with the version of CUDA or ROCm installed.

On Linux, you may need to set LD_LIBRARY_PATH environment variable depending on how you installed CUDA/ROCm.
On Windows, try setting CUDA_PATH environment variable.

Check the Installation Guide for details:
  https://docs.cupy.dev/en/latest/install.html

Original error:
  ImportError: libcudart.so.12: cannot open shared object file: No such file or directory
================================================================


---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

看来我需要卸载cupy-cuda11x,所以我将其卸载为

pip uninstall cupy-cuda11x
。 然后我尝试再次导入 cupy 作为

import cupy
cupy.arange(3)

我收到了不同的错误消息,

AttributeError                            Traceback (most recent call last)
<ipython-input-8-0a93c279befd> in <cell line: 2>()
      1 import cupy
----> 2 cupy.arange(3)

AttributeError: module 'cupy' has no attribute 'arange'

就像,cupy 模块是空的。

关于CUDA兼容性,Colab的CUDA版本为11.8,兼容CuPy 12.2。

>>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

  1. 当我尝试使用命令
    pip install cupy
    安装 cupy 时,我收到以下错误消息。
Building wheels for collected packages: cupy
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for cupy (setup.py) ... error
  ERROR: Failed building wheel for cupy
  Running setup.py clean for cupy
Failed to build cupy
ERROR: Could not build wheels for cupy, which is required to install pyproject.toml-based projects

此时,我不知道如何解决它。


  1. 当我尝试按照推荐安装cupy时,
pip install chainer
curl https://colab.chainer.org/install | sh -

我刚刚收到以下错误消息,我放弃了。运行时类型选择为 T4 GPU。

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1553  100  1553    0     0  12757      0 --:--:-- --:--:-- --:--:-- 12834
********************************************************************************
CUDA version could not be detected!
Try installing Chainer manually by: pip install chainer
********************************************************************************
installation cuda google-colaboratory setup.py cupy
1个回答
0
投票

CuPy 默认安装在 Google Colab 上,因此您只需

import cupy
即可。如果您喜欢最新版本的 CuPy,请尝试
pip install -U cupy-cuda11x

© www.soinside.com 2019 - 2024. All rights reserved.