Problem
- I tried to install PyCUDA using
pip
:
$ sudo pip install pycuda
- The installation tries to compile a few C++ files and it failed on the very first file with this error:
In file included from src/cpp/cuda.cpp:1:0: src/cpp/cuda.hpp:14:18: fatal error: cuda.h: No such file or directory #include <cuda.h> ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Investigation
- This error was strange because I had set
CUDA_ROOT
and had added thebin
path of CUDA installation toPATH
environment variable. So, the installer should have foundcuda.h
which I could see was present in$CUDA_ROOT/include
-
To see what was happening, I tried the same command with verbosity:
$ sudo pip -vvv install pycuda
-
Now I could see that it was failing to find
nvcc
. -
On downloading the source code of PyCUDA and checking
setup.py
, I saw that the check fornvcc
was used to figure out theCUDA_ROOT
andCUDA_INC_DIR
. -
The reason
nvcc
was not visible was thatCUDA_ROOT
was set for my user, but thisPATH
is not visible when a command is run undersudo
, as described here. The solution was to make the CUDAbin
path visible tosudo
.
Solution
To make the $CUDA_ROOT/bin
available in PATH
for sudo
, we can follow the steps described here. For example, on my system with CUDA 7.0 I followed these steps:
- Created a new file
/etc/profile.d/cuda.sh
and added this line:
export PATH=/usr/local/cuda-7.0/bin:$PATH
- Opened
root
shell without resettingPATH
and ran the pip installation:
$ sudo su - $ pip install pycuda
This worked and PyCUDA was installed successfully! 🙂
Tried with: PyCUDA 2015.1.2, CUDA 7.0 and Ubuntu 14.04
Thanks mate, It was really simplified.
LikeLike
many many thanks for sharing. You helped me
LikeLike
Thank you for sharing!
I come with the same error, but I’m not the administrator. How could I do?
LikeLike
Super thanks! I searched for a thousand year and only you helped me out of this
LikeLike
thanks.. this worked..
LikeLike
thanks a lot!!
LikeLike