为啥导入 cugraph 在 kaggle 中不起作用?

Posted

技术标签:

【中文标题】为啥导入 cugraph 在 kaggle 中不起作用?【英文标题】:why import cugraph not working in kaggle?为什么导入 cugraph 在 kaggle 中不起作用? 【发布时间】:2022-01-05 01:45:19 【问题描述】:

我需要在 kaggle 中使用 cugraph,因为我使用以下代码安装了 rapids:

    import sys
!cp ../input/rapids/rapids.21.06 /opt/conda/envs/rapids.tar.gz
!cd /opt/conda/envs/ && tar -xzvf rapids.tar.gz > /dev/null
sys.path = ["/opt/conda/envs/rapids/lib/python3.7/site-packages"] + sys.path
sys.path = ["/opt/conda/envs/rapids/lib/python3.7"] + sys.path
sys.path = ["/opt/conda/envs/rapids/lib"] + sys.path 
!cp /opt/conda/envs/rapids/lib/libxgboost.so /opt/conda/lib/

那么,

conda install -c nvidia -c rapidsai -c numba -c conda-forge -c defaults cugraph cudatoolkit=10.2

但没有安装cugraph,通常我有这个错误:

 ModuleNotFoundError                       Traceback (most recent call last) /tmp/ipykernel_241/370751810.py in <module>
----> 1 import cugraph

ModuleNotFoundError: No module named 'cugraph'

当我尝试在安装中使用 !pip 时,我收到此错误:

Collecting cugraph
  Using cached cugraph-0.6.1.post1.tar.gz (1.1 kB)
Building wheels for collected packages: cugraph
  Building wheel for cugraph (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /opt/conda/bin/python3.7 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vayp36a0/cugraph_6683f309da3e4f3da55486b6a34ad47d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vayp36a0/cugraph_6683f309da3e4f3da55486b6a34ad47d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-nar691rc
       cwd: /tmp/pip-install-vayp36a0/cugraph_6683f309da3e4f3da55486b6a34ad47d/
  Complete output (25 lines):
  running bdist_wheel
  running build
  installing to build/bdist.linux-x86_64/wheel
  running install
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-vayp36a0/cugraph_6683f309da3e4f3da55486b6a34ad47d/setup.py", line 35, in <module>
      cmdclass='install': InstallWrapper,
    File "/opt/conda/lib/python3.7/site-packages/setuptools/__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "/opt/conda/lib/python3.7/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/opt/conda/lib/python3.7/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/opt/conda/lib/python3.7/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/opt/conda/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 335, in run
      self.run_command('install')
    File "/opt/conda/lib/python3.7/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/opt/conda/lib/python3.7/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-vayp36a0/cugraph_6683f309da3e4f3da55486b6a34ad47d/setup.py", line 15, in run
      raise Exception(long_description)
  Exception: Please install cugraph via the rapidsai conda channel. See https://rapids.ai/start.html for instructions.
  ----------------------------------------
  ERROR: Failed building wheel for cugraph

【问题讨论】:

为什么不!pip install ... 不工作!pip 安装 你有什么错误吗?始终将有问题的完整错误消息(从“Traceback”一词开始)(不在 cmets 中)作为文本(不是屏幕截图,不链接到外部门户)。还有其他有用的信息。 @furas,我编辑帖子并在尝试使用 !pip install cugraph 时输入错误 你能确认你的jupyter内核实际上是在使用环境的python吗?在单元格中运行print(sys.executable()) 并检查它是否指向/opt/conda/envs/rapids 【参考方案1】:

为了将来的读者参考,完整的答案在这里详述:

https://github.com/rapidsai/cugraph/issues/1972#issuecomment-982925312

用户需要指定 RPAIDS 版本、python 版本和 CUDA 工具包版本。在撰写本文时,Kaggle 的工作 conda install 命令是:

!conda install -y -c rapidsai -c nvidia -c conda-forge cugraph=21.08 python=3.7 cudatoolkit=11.0

【讨论】:

以上是关于为啥导入 cugraph 在 kaggle 中不起作用?的主要内容,如果未能解决你的问题,请参考以下文章

为啥方法重命名在 PHP 特征中不起作用?

为啥 doctest 在 qpython3 中不起作用

为啥 IOCP 在 BeginExecuteReader 中不起作用

为啥 setVisibility() 在 onResumeFragments() 中不起作用?

为啥 heightForHeaderInSection 在 iOS 4.3 中不起作用?

为啥复制功能在 setTimeout 中不起作用?