Can't install pycuda

Good mooring. I have some problems with the installation of pycuda on ubuntu 22.04 with python 3.10.6 and NVIDIA GeForce RTX 3060 Laptop GPU.
I have installed cuda library, if I type the command

nvidia-smi

I get the usual frame displaying the driver version: NVIDIA-SMI 525.60.13 Driver Version: 525.60.13 CUDA Version: 12.0 .
Also, I have tried to run a simple cuda code and everything runs smoothly.
I have tried to install pycuda wit the following command -pip-

 pip install pycuda

Regrettably the procedure ends with the following error message -I attach only the final part since the whole message is huge-

     /usr/include/c++/11/bits/unique_ptr.h:57:28: note: declared here
         57 |   template<typename> class auto_ptr;
            |                            ^~~~~~~~
      In file included from bpl-subset/bpl_subset/boost/bind/bind.hpp:29,
                       from bpl-subset/bpl_subset/boost/bind.hpp:22,
                       from bpl-subset/bpl_subset/boost/thread/detail/thread.hpp:23,
                       from bpl-subset/bpl_subset/boost/thread/thread.hpp:22,
                       from bpl-subset/bpl_subset/libs/thread/src/pthread/thread.cpp:11:
      bpl-subset/bpl_subset/boost/bind/arg.hpp: In constructor ‘pycudaboost::arg<I>::arg(const T&)’:
      bpl-subset/bpl_subset/boost/bind/arg.hpp:37:22: warning: typedef ‘T_must_be_placeholder’ locally defined but not used [-Wunused-local-typedefs]
         37 |         typedef char T_must_be_placeholder[ I == is_placeholder<T>::value? 1: -1 ];
            |                      ^~~~~~~~~~~~~~~~~~~~~
      In file included from bpl-subset/bpl_subset/boost/thread/thread.hpp:24,
                       from bpl-subset/bpl_subset/libs/thread/src/pthread/thread.cpp:11:
      bpl-subset/bpl_subset/boost/thread/detail/thread_group.hpp: In member function ‘pycudaboost::thread* pycudaboost::thread_group::create_thread(F)’:
      bpl-subset/bpl_subset/boost/thread/detail/thread_group.hpp:42:18: warning: ‘template<class> class std::auto_ptr’ is deprecated: use 'std::unique_ptr' instead [-Wdeprecated-declarations]
         42 |             std::auto_ptr<thread> new_thread(new thread(threadfunc));
            |                  ^~~~~~~~
      In file included from /usr/include/c++/11/memory:76,
                       from bpl-subset/bpl_subset/boost/move/move.hpp:38,
                       from bpl-subset/bpl_subset/boost/thread/detail/move.hpp:20,
                       from bpl-subset/bpl_subset/boost/thread/locks.hpp:11,
                       from bpl-subset/bpl_subset/boost/thread/pthread/thread_data.hpp:11,
                       from bpl-subset/bpl_subset/boost/thread/thread.hpp:17,
                       from bpl-subset/bpl_subset/libs/thread/src/pthread/thread.cpp:11:
      /usr/include/c++/11/bits/unique_ptr.h:57:28: note: declared here
         57 |   template<typename> class auto_ptr;
            |                            ^~~~~~~~
      bpl-subset/bpl_subset/libs/thread/src/pthread/thread.cpp: In member function ‘bool pycudaboost::thread::do_try_join_until(const timespec&)’:
      bpl-subset/bpl_subset/libs/thread/src/pthread/thread.cpp:379:5: warning: control reaches end of non-void function [-Wreturn-type]
        379 |     }
            |     ^
      x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -fwrapv -Wall -O3 -DNDEBUG -fPIC -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_BUILD_DLL=1 -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION=1 -DBOOST_PYTHON_SOURCE=1 -Dboost=pycudaboost -DBOOST_THREAD_DONT_USE_CHRONO=1 -DPYGPU_PACKAGE=pycuda -DPYGPU_PYCUDA=1 -DHAVE_CURAND=1 -Isrc/cpp -Ibpl-subset/bpl_subset -I/tmp/pip-build-env-sr08yzu7/overlay/local/lib/python3.10/dist-packages/numpy/core/include -I/usr/include/python3.10 -c src/cpp/bitlog.cpp -o build/temp.linux-x86_64-cpython-310/src/cpp/bitlog.o
      x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -fwrapv -Wall -O3 -DNDEBUG -fPIC -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_BUILD_DLL=1 -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION=1 -DBOOST_PYTHON_SOURCE=1 -Dboost=pycudaboost -DBOOST_THREAD_DONT_USE_CHRONO=1 -DPYGPU_PACKAGE=pycuda -DPYGPU_PYCUDA=1 -DHAVE_CURAND=1 -Isrc/cpp -Ibpl-subset/bpl_subset -I/tmp/pip-build-env-sr08yzu7/overlay/local/lib/python3.10/dist-packages/numpy/core/include -I/usr/include/python3.10 -c src/cpp/cuda.cpp -o build/temp.linux-x86_64-cpython-310/src/cpp/cuda.o
      In file included from src/cpp/cuda.cpp:4:
      src/cpp/cuda.hpp:14:10: fatal error: cuda.h: No such file or directory
         14 | #include <cuda.h>
            |          ^~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' 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 pycuda
Failed to build pycuda
ERROR: Could not build wheels for pycuda, which is required to install pyproject.toml-based projects

I have already tried to use the following command but with no improvements:

 pip3 install pycuda
 pip install pycuda --user

Thank you for the time dedicated to read this post.
If this not the most relevant section, please move the topic in the most appropriate one.
Best regards.
Giovanni.

Good morning, I have solved the problem with the following instructions. I hope this can help others with the same problem in future:

$ export PATH=/usr/local/cuda/bin:$PATH
$ export CUDA_ROOT=/usr/local/cuda
$ pip install pycuda

Best regards.
Giovanni.

3 Likes

try pipwin install pycuda