Failed building wheel for pycuda
...In file included from src/cpp/cuda.cpp:4:src/cpp/cuda.hpp:14:10: fatal error: cuda.h: 没有那个文件或目录14 | #include <cuda.h>| ^~~~~~~~compilation terminated.error: command '/usr/bin/g++' failed with exit code 1[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.ERROR: Failed building wheel for pycudaDEPRECATION: Building 'nvidia-pyindex' using the legacy setup.py bdist_wheel mechanism, which will be removed in a future version. pip 25.3 will enforce this behaviour change. A possible replacement is to use the standardized build interface by setting the `--use-pep517` option, (possibly combined with `--no-build-isolation`), or adding a `pyproject.toml` file to the source tree of 'nvidia-pyindex'. Discussion can be found at https://github.com/pypa/pip/issues/6334Building wheel for nvidia-pyindex (setup.py) ... doneCreated wheel for nvidia-pyindex: filename=nvidia_pyindex-1.0.9-py3-none-any.whl size=8510 sha256=ddc833868c516fe46860ba0ce38fd6cfea94912dc8107825be013a422e53e973Stored in directory: /home/wangguisen/.cache/pip/wheels/30/9f/d7/10a73e63166091b744d10c631596f2c7e53ac14a41b9246de5
Successfully built nvidia-pyindex
Failed to build pycuda
ERROR: Failed to build installable wheels for some pyproject.toml based projects (pycuda)
这个错误表明在编译 pycuda 包时,系统无法找到 cuda.h 文件。这通常是因为以下几个原因:
- CUDA Toolkit 未安装:cuda.h 文件是 CUDA Toolkit 的一部分,如果没有安装 CUDA Toolkit,就会出现这个错误。
- CUDA Toolkit 安装路径不正确:即使安装了 CUDA Toolkit,如果其路径未正确配置,编译器也可能找不到 cuda.h 文件。
- 环境变量未设置或设置不正确:编译器需要通过环境变量(如 CUDA_HOME 和 LD_LIBRARY_PATH)来找到 CUDA Toolkit 的路径。
先运行:
nvcc -V
如果提示:
找不到命令 “nvcc”,但可以通过以下软件包安装它:
apt install nvidia-cuda-toolkit
请联系您的管理员。
先确定是不是安装了,很有可能是安装了但是环境变量没有配:
ls /usr/local/cuda# 如果你看到类似以下的输出,说明 CUDA Toolkit 已经安装:
# bin include lib64 share ...
如果你已经安装了 CUDA Toolkit,但系统无法找到 nvcc 命令,可能是因为 CUDA Toolkit 的路径没有添加到系统的 PATH 环境变量中。你可以通过以下命令临时添加路径:
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
为了永久生效,你可以将这些行添加到你的 ~/.bashrc 文件中:
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
如果你没有安装 CUDA Toolkit,可以根据提示安装,注意和cuda版本对应,记得写入环境变量。
sudo apt-get install nvidia-cuda-toolkit